P5715 【深基3.例8】三位数排序 题解

元气小坏坏 提交于 2020-01-14 07:23:04

快读做法

#include <iostream>
#include <algorithm>//sort
#include <cstdio>
using namespace std;

int x[5]={};
inline int _read(){
    int x=0;char ch = getchar();
    while (!isdigit(ch))ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}

int main(){
    x[0]=_read(); x[1]=_read(); x[2]=_read();
    sort(x,x+3);
    for (int i=0; i<=2; i++){
	    cout << x[i] << ' ';
    }
    return 0;
}

ps:sort的语法

sort(begin, end, cmp)
其中begin指向待sort()的数组的第一个元素,end指向待sort()的数组的最后一个元素的下一个位置,cmp参数为排序准则,如果没有的话,默认从小到大排序。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!