L1-010 比较大小 (10分)
本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:
4 2 8
输出样例:
2->4->8
答案
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
int x = max(max(a,b),max(b,c));
if(x == b){
b = a;
a = x;
}else if(x == c){
c = a;
a = x;
}
int y = max(b, c);
if(y == c){
c = b;
b = y;
}
printf("%d->%d->%d", c, b, a);
return 0;
}
或许可能上述判断过程复杂了点,不过似乎也没复杂到哪里去emm就这样
总看错题哎,以为从大到小的顺序,用了max(), 还好后面输出把a , c 换一下位置就好
NEXT