阅读671 返回首页    go 阿里云 go 技术社区[云栖]


5个数求最值

5个数求最值

时间限制:1000 ms  |  内存限制:65535 KB
描述
设计一个从5个整数中取最小数和最大数的程序
输入
输入只有一组测试数据,为五个不大于1万的正整数
输出
输出两个数,第一个为这五个数中的最小值,第二个为这五个数中的最大值,两个数字以空格格开。
样例输入
1 2 3 4 5
样例输出
1 5
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> v;
    int a;

    for (int i = 0; i < 5; i++)
    {
        scanf("%d", &a);
        v.push_back(a);
    }

    printf("%d %d\n", *min_element(v.begin(), v.end()), *max_element(v.begin(), v.end()));
    return 0;
}


最后更新:2017-04-02 15:14:59

  上一篇:go 水仙花数
  下一篇:go STL中Algorithm