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

  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. #include<vector>
  5. using namespace std;
  6. #define maxn 10000
  7. int ipos=0;
  8. class MaxValue
  9. {
  10. public:
  11. int a[maxn];
  12. void append(int t)
  13. {
  14. a[ipos++]=t;
  15. }
  16. int getMax()
  17. {
  18. return *max_element(a,a+ipos);
  19. }
  20. };
  21. int main()
  22. {
  23. int a;
  24. MaxValue test;
  25. cin>>a;
  26. while (a != 0)
  27. {
  28. test.append(a);
  29. cin>>a;
  30. }
  31. cout<<test.getMax()<<endl;
  32. return 0;
  33. }

  

Problem J: 求个最大值的更多相关文章

  1. Problem C: 求个最大值

    class MaxValue { public: vector<int> vec; void append(int n) { vec.push_back(n); } int getMax( ...

  2. Problem J: 求方程的解——C语言初学者百题大战之十五

    #include<stdio.h> #include<math.h> int main() { float a,b,c,x1,x2,delta; scanf("%f ...

  3. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  4. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  5. Problem N: 求二维数组中的鞍点【数组】

    Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2764  Solved: 1728[Submit][S ...

  6. 实验12:Problem F: 求平均年龄

    Home Web Board ProblemSet Standing Status Statistics   Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...

  7. 实验12:Problem J: 动物爱好者

    #define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...

  8. 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, ...

  9. Problem J. Journey with Pigs

    Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...

随机推荐

  1. Longge's problem poj2480 欧拉函数,gcd

    Longge's problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6918   Accepted: 2234 ...

  2. mysql-5.7.17-winx64解压版本安装图解附带一些常见问题

    第一步:下载mysql-5.7.17-winx64解压版本:http://dev.mysql.com/downloads/mysql/ 第二步:解压到安装目录,如:D:\MySql\mysql-5.7 ...

  3. CPU 分类

    Single Core :单核CPU Dual Core   :双核CPU Quad Core  :四核CPU Hexa Core  :六核CPU Octa Core   :八核CPU 参考: htt ...

  4. Web服务器自定义错误页面

    在使用Web服务器运行程序的时候,难免会出现诸如 404.500 等错误,那么如何针对不同的错误代码来自定义错误页面呢? 1.找到web项目的 web.xml 文件打开,添加以下标签代码,规则是 er ...

  5. java 学习笔记 读取配置文件的三种方式

    package com.itheima.servlet.cfg; import java.io.FileInputStream; import java.io.FileNotFoundExceptio ...

  6. 百度SMS SDK for .Net

    SMS 服务用于向指定的手机号码发送短信. 百度SMS提供了C, JAVA, Python的官方SDK,本项目依据API封装了面向.net的库,目前已经实现了基本的短信发送功能. 项目Github开源 ...

  7. C#微信公众号/订阅号开发 接口源码

    using System; using System.Web; using System.IO; using System.Text; using System.Web.Security; using ...

  8. 【实验吧】Once More

    <?php if (isset ($_GET['password'])) { if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) = ...

  9. 我的第一个python web开发框架(7)——本地部署前端访问服务器

    PS:本系列内容进度节奏会放的很慢,每次知识点都尽量少一点,这样大家接触的知识点少了,会更容易理解,因为少即是多.另外,对于后面代码部分,虽然尽量不用那些复杂的封装和类,但它并不表示看了就能全部记住, ...

  10. C#类的学习

    ①类的定义是以关键字 class 开始,后跟类的名称.类的主体,包含在一对花括号内.下面是类定义的一般形式: 类的修饰符 class 类名 :继承的类{ //类的成员 } 请注意: 如果要访问类的成员 ...