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

append.cc,

#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;
}

  

时间: 2024-08-02 06:56:25

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

Problem A: 求个最大值

Problem A: 求个最大值 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1635  Solved: 1339[Submit][Status][Web Board] Description 定义MaxValue类,用于求一系列非零整数的最大值.其中: 1. 数据成员elements用于存储所有输入的非零整数. 2. void append(int)用于向elements中添加一个新数据. 3. int getMax()用于求出elements

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

#include<stdio.h> #include<math.h> int main() { float a,b,c,x1,x2,delta; scanf("%f %f %f",&a,&b,&c); delta=b*b-4*a*c; if(a==0){ if(b==0) printf("No\n"); else printf("%f\n",(-c)/b); } if(a!=0){ if(delta

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

Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The travel agency “Four Russians” is offering the new service for their clients. Unlike other agencies that only suggest one-way

Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Parmida is a clever girl and she wants to participate in O

求条件最大值

求条件最大值 Time Limit: 1000MS Memory limit: 65536K 题目描述 懒得想背景故事了,开门见山. 有一个长度为n的整数数列A0,A1,A2....An-1.从中找出两个整数Ai和Aj,Ai在Aj的前面,即i<j,使得Ai-Aj尽可能的大.请输出可能的最大的Ai-Aj的值. 输入 多组输入.每一组测试数据的第一行是一个整数n,然后第二行是n个整数,第i个数 表示Ai.(测试数据组数<=20,2<=n<=10^6,-10^8<=Ai<=1

树状数组求区间最大值

------  一直用 线段树 求区间最大值,想换种思路,用树状数组试试,肯定是可以的. 首先要对 树状数组的每个 i 所管理的区间有一定的理解.详见上篇博客: 树状数组(BIT)

1010 求个最大值

1010: 求个最大值 时间限制: 1 Sec  内存限制: 128 MB提交: 231  解决: 39[提交][状态][讨论版] 题目描述 给出 n(1 <= n <= 200000)个数字 ai(1 <= ai <= 1000000),i 为数字的下标,按输入顺序从 1 开始编号一直到 n,求满足 ai >= aj 的最大的 ai % aj. 输入 第一行一个数字 n,第二行 n 个整数. 输出 题目要求的最大值. 样例输入 2 2 3 样例输出 1 提示

XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

题目:Problem J. TerminalInput file: standard inputOutput file: standard inputTime limit: 2 secondsMemory limit: 256 mebibytesN programmers from M teams are waiting at the terminal of airport. There are two shuttles at the exitof terminal, each shuttle

29.求数组最大值

import java.util.Scanner; public class MaxScore { /** * 求数组最大值 */ public static void main(String[] args) { int[] scores = new int[5]; int max = 0; //记录最大值 System.out.println("请输入5位学员的成绩:"); Scanner input = new Scanner(System.in); for(int i = 0;