Problem B: 求个最大值
Time Limit: 1 Sec
Memory Limit: 128 MB
Submit: 951
Solved: 732
Description
定义MaxValue类,用于求一系列非零整数的最大值。其中:
1. 数据成员elements用于存储所有输入的非零整数。
2. void append(int)用于向elements中添加一个新数据。
3. int getMax()用于求出elements中的最大值。
Input
输入若干个整数,以输入0表示输入结束。
Output
所有输入的非零整数中的最大值。
Sample Input
3214965533388374631581549295370
Sample Output
929
HINT
使用vector更为容易实现。
Append Code
한국어< 中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include <iostream>
#include <vector>
using namespace std;
class MaxValue
{
public:
void append(int x) { c.push_back(x); }
int getMax()
{
vector<int>::iterator v;
int max_ = 0;
for(v = c.begin(); v != c.end(); v++)
{
if(max_ < *v)
max_ = *v;
}
return max_;
}
public:
MaxValue() { }
private:
vector<int> c;
};
int main()
{
int a;
MaxValue test;
cin>>a;
while (a != 0)
{
test.append(a);
cin>>a;
}
cout<<test.getMax()<<endl;
return 0;
}