1447 - C语言-排序
输入三个整数,按由小到大的顺序输出。
Input
三个整数
Output
由小到大输出成一行,每个数字后面跟一个空格
Examples
Input
2 3 1
Output
1 2 3
Solution C
int main(int argc, char* argv[]) { int a,b,c,tem; while(~scanf("%d%d%d",&a,&b,&c)) { if(a>b) { tem=a; a=b; b=tem; } if(a>c) { tem=a; a=c; c=tem; } if(b>c) { tem=c; c=b; b=tem; } printf("%d %d %d \n",a,b,c); } return 0; }
Solution C++
#include <iostream> #include<cstdio> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a<b&&b<c) {cout <<a<< " " <<b<< " " <<c<<" " << endl;} else if(a<c&&c<b) {cout <<a<< " " <<c<< " " <<b<<" " << endl;} else if(b<a&&a<c) {cout <<b<< " " <<a<< " " <<c<<" " << endl;} else if(b<c&&c<a) {cout <<b<< " " <<c<< " " <<a<<" " << endl;} else if(c<a&&a<b) {cout <<c<< " " <<a<< " " <<b<<" " << endl;} else {cout <<c<< " " <<b<< " " <<a<<" " << endl;} return 0; }