zoukankan      html  css  js  c++  java
  • nyoj 31 5个数求最值

    5个数求最值

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

    分析:直接用algorithm中的*min_element()和*max_element()。或者先排序,取首尾。
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <vector>
     4 using namespace std;
     5 int main(){
     6     vector<int> v(5);
     7     for(int i = 0; i < 5; i++)
     8         cin >> v[i];
     9     //sort(v.begin(), v.end());
    10     cout << *min_element(v.begin(), v.end()) << " ";
    11     cout << *max_element(v.begin(), v.end()) << endl;
    12     //cout << v[0] << " " << v[4] << endl;
    13     return 0;
    14 }
  • 相关阅读:
    word 操作技巧
    有朝一日
    菜狗日记2021.7.10
    记一次JSON.toJSONString()踩坑
    菜狗日记2020.11.13
    菜狗日记2020.11.6
    菜狗日记2020.11.03
    菜狗日记2020.10.29
    菜狗日记2020.10.17
    菜狗日记2020.10.11
  • 原文地址:https://www.cnblogs.com/qinduanyinghua/p/6394413.html
Copyright © 2011-2022 走看看