Problem J: 求个最大值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

321 496 553 338 837 463 158 154 929 537 0

Sample Output

929

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: 求个最大值的主要内容,如果未能解决你的问题,请参考以下文章

loj6158 A+B Problem (扩展KMP)

POJ-2452 Sticks Problem 二分+RMQ

noip提高组2013 火柴排队

1010 求个最大值

hdu6219(最大空凸包)

HDU 1032 [The 3n + 1 problem] 暴力模拟