Problem J: 求个最大值
Problem J: 求个最大值
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 871 Solved: 663
[Submit][Status][Web Board]
Description
定义MaxValue类,用于求一系列非零整数的最大值。其中:
1. 数据成员elements用于存储所有输入的非零整数。
2. void append(int)用于向elements中添加一个新数据。
3. int getMax()用于求出elements中的最大值。
Input
输入若干个整数,以输入0表示输入结束。
Output
所有输入的非零整数中的最大值。
Sample Input
496
553
338
837
463
158
154
929
537
0
Sample Output
HINT
使用vector更为容易实现。
Append Code
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define maxn 10000
int ipos=0;
class MaxValue
{
public:
int a[maxn];
void append(int t)
{
a[ipos++]=t;
}
int getMax()
{
return *max_element(a,a+ipos);
}
};
int main()
{
int a;
MaxValue test;
cin>>a;
while (a != 0)
{
test.append(a);
cin>>a;
}
cout<<test.getMax()<<endl;
return 0;
}
Problem J: 求个最大值的更多相关文章
- Problem C: 求个最大值
class MaxValue { public: vector<int> vec; void append(int n) { vec.push_back(n); } int getMax( ...
- Problem J: 求方程的解——C语言初学者百题大战之十五
#include<stdio.h> #include<math.h> int main() { float a,b,c,x1,x2,delta; scanf("%f ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
- Problem N: 求二维数组中的鞍点【数组】
Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2764 Solved: 1728[Submit][S ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 实验12:Problem J: 动物爱好者
#define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J Joking with Fermat's Last Theorem Fermat's Last Theorem: no three positive integers a, b, ...
- Problem J. Journey with Pigs
Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...
随机推荐
- 第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ----初始化一个线程
使用线程的一个常见问题就是如何能够在一个线程开始运行之前,适当地将它初始化.初始化最常见的理由就是为了调整优先权.另一个理由是为了在SMP 系统中设定线程比较喜欢的 CPU.第10 章谈到 MFC 时 ...
- Rundeck部署和基本使用
rundeck 介绍 Rundeck 是一款能在数据中心或云环境中的日常业务中使程序自动化的开源软件.Rundeck 提供了大量功能,可以减轻耗时繁重的体力劳动.团队可以相互协作,分享如何过程自动化, ...
- HAProxy安装文档
HAProxy安装文档 [toc][TOC] 一.环境说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64 软 ...
- SqlServer和Oracle中一些常用的sql语句5 流程控制语句
--在sql语句中 begin...end 用来设定一个程序块 相关于c#中的{} declare @yz real,@w int --声明变量 set @w=120 --为变量赋值 if @w< ...
- swiper 初始化的两个小坑
1.当swiper loop设为true时,同时你又改变了sliderPerview的值,这时候轮播,按prev按钮到第一个时,会出现空白页: 解决办法:sliderPerview设置为auto,lo ...
- ReactiveCocoa_v2.5 源码解析之架构总览
ReactiveCocoa 是一个 iOS 中的函数式响应式编程框架,它受 Functional Reactive Programming 的启发,是 Justin Spahr-Summers 和 J ...
- This application failed to start because it could not find or load the Qt platform plugin "windows" 的问题原因以及解决方案
1. 问题原因非常简单,经过各种百度,都没有找到解决方案,在此做一个记录备用. 2.原因就在于,项目目录使用了中文路径,然后出现了这个问题. 3.我是在使用 syncfusion 下的HTML 转PD ...
- Django REST framework 中文教程1:序列化
建立环境 在我们做任何事情之前,我们将使用virtualenv创建一个新的虚拟环境.这将确保我们的包配置与我们正在开展的任何其他项目保持良好的隔离. virtualenv envsource env/ ...
- invalid types 'int[int]' for array subscript// EOF 输入多组数据//如何键盘输入EOF
数组维度搞错了 一次运行,要输入多组数据,直到读至输入文件末尾(EOF)为止 while(scanf("%d %d",&a, &b) != EOF) // 输入结束 ...
- win10 uwp 隐私声明
本文讲的是如何去写隐私声明. 垃圾微软要求几乎每个应用都要有隐私声明,当然如果你不拿用户信息的话,那么用户声明是一个URL,我们应该把应用声明放在哪? 其实我们简单方法是把隐私声明Privacy Po ...