现在的位置: 首页 > 综合 > 正文

jobdu1046:求最大值

2017年11月17日 ⁄ 综合 ⁄ 共 528字 ⁄ 字号 评论关闭

http://ac.jobdu.com/problem.php?pid=1046

题目描述:

输入10个数,要求输出其中的最大值。

输入:

测试数据有多组,每组10个数。

输出:

对于每组输入,请输出其最大值(有回车)。

样例输入:
10 22 23 152 65 79 85 96 32 1
样例输出:
max=152

#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
    int max = -99999999;
    int i = 0, a;
    while(scanf("%d", &a) != EOF) {
        if(a > max)
            max = a;
        if(++i%10 == 0) {
            printf("max=%d\n", max);
            max = -99999999;
        }
    }
    return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[10];
    while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7] >> a[8] >> a[9]) {
        sort(a, a+10);
        cout << "max=" << a[9] << endl;
        }
    return 0;
}

抱歉!评论已关闭.