nyoj 41-三个数从小到大排序(STL --> sort(a, a+n) 升序)

41-三个数从小到大排序


内存限制:64MB 时间限制:3000ms Special Judge: No
accepted:31 submit:44

题目描述:

现在要写一个程序,实现给三个数排序的功能

输入描述:

输入三个正整数

输出描述:

给输入的三个正整数排序

样例输入:

20 7 33

样例输出:

7 20 33

分析:  
  直接使用STL库中的sort函数进行排序

C/C++代码实现(AC):
  
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main()
{

    int t[3];
    scanf("%d%d%d", &t[0], &t[1], &t[2]);
    sort(t, t+3);
    for(int i = 0; i < 2; ++ i)
        printf("%d ", t[i]);
    printf("%d
", t[2]);
    return 0;
}



原文地址:https://www.cnblogs.com/GetcharZp/p/9074386.html