定义MaxValue类,用于求一系列非零整数的最大值。其中:
1. 数据成员elements用于存储所有输入的非零整数。
2. void append(int)用于向elements中添加一个新数据。
3. int getMax()用于求出elements中的最大值。
标签:output rip app algorithm page problems class php main
定义MaxValue类,用于求一系列非零整数的最大值。其中:
1. 数据成员elements用于存储所有输入的非零整数。
2. void append(int)用于向elements中添加一个新数据。
3. int getMax()用于求出elements中的最大值。
输入若干个整数,以输入0表示输入结束。
所有输入的非零整数中的最大值。
使用vector更为容易实现。
#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; }
标签:output rip app algorithm page problems class php main
原文地址:http://www.cnblogs.com/masterchd/p/6935179.html