Problem A: 求个最大值

Problem A: 求个最大值

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1635   Solved: 1339
[ Submit][ Status][ Web Board]

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

[ Submit][ Status][ Web Board]
#include<bits/stdc++.h>
using namespace std;
class MaxValue{ 
private
vector < int > elements; 
public
      void append( int n) 
     
          elements.push_back(n); 
     
    
      int getMax() 
     
      vector< int >::iterator max ; 
      max= max_element(elements.begin(), elements.end()); 
      return *max; 
     
    
}; 
int main()
{
     int a;
     MaxValue test;
     cin>>a;
     while (a != 0)
     {
         test.append(a);
         cin>>a;
     }
     cout<<test.getMax()<<endl;
     return 0;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值