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
496
553
338
837
463
158
154
929
537
0
Sample Output
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: 求个最大值的更多相关文章
- Problem C: 求个最大值
class MaxValue { public: vector<int> vec; void append(int n) { vec.push_back(n); } int getMax( ...
- Problem J: 求方程的解——C语言初学者百题大战之十五
#include<stdio.h> #include<math.h> int main() { float a,b,c,x1,x2,delta; scanf("%f ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量
Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...
- Problem N: 求二维数组中的鞍点【数组】
Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2764 Solved: 1728[Submit][S ...
- 实验12:Problem F: 求平均年龄
Home Web Board ProblemSet Standing Status Statistics Problem F: 求平均年龄 Problem F: 求平均年龄 Time Limit: ...
- 实验12:Problem J: 动物爱好者
#define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...
- 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, ...
- Problem J. Journey with Pigs
Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...
随机推荐
- Find 找规律,递推
Find Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus P ...
- jQuery ajax的提交
1.利用jQuery中的aja提交数据,首先引入jQuery中的文件 2.jquery.form.js下载地址:http://vdisk.weibo.com/s/thY_x31gX0M-p?categ ...
- 【框架学习与探究之宿主服务--Topshelf】
前言 此文欢迎转载,原始链接地址:http://www.cnblogs.com/DjlNet/p/7603819.html 正文 原先也偶然见过这个关键词,当时只是有个大致了解貌似和WinServic ...
- MVC3/4/5/6 布局页及Razor语法及Route路由配置
一.目录结构 二.Razor语法 代码块:@{},如:@{Html.Raw(“”);} @if(){} @switch(){} @for(){} @foreach(){} @while(){} @do ...
- 使用Fabric一键批量部署上线/线上环境监控
本文讲述如何使用fabric进行批量部署上线的功能 这个功能对于小应用,可以避免开发部署上线的平台,或者使用linux expect开发不优雅的代码. 前提条件: 1.运行fabric脚本的机器和其他 ...
- px转vw和vh的工具(对前端同学有用)
CSS3中有两个新尺寸单位vw和vh, 这两个单位非常适合于开发移动端自适应页面. 假如说有一个设计师做了一张1136x750px的页面,这长页面是针对iPhone6的屏幕设计的. 前端开发工程师将这 ...
- Masonry框架源码深度解析
Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...
- 容器平台选型的十大模式:Docker、DC/OS、K8S 谁与当先?
作者:刘超 来自:网易云 基础服务 无论是在社区,还是在同客户交流的过程中,总会被问到到底什么时候该用 Docker?什么时候用虚拟机?如果使用容器,应该使用哪个容器平台? 显而易见,我不会直接给 ...
- Gradle sync failed 异常
今天开发过程中出现如下异常 Gradle sync failed: Connection timed out: connect. If you are behind an HTTP proxy, pl ...
- Python基础3切片,字符串的方法
切片:截取字符串某一段字符,并不改变原字符串.结构:[起始位置:终止位置:步长] 但不包括终止位置.所谓:顾头不顾尾 索引:序列中每个元素都是有编号的,都是从0开始编号的.使用负数索引时,Pytho ...