本文共 1229 字,大约阅读时间需要 4 分钟。
(1)
#include#include using namespace std;intcmp(int a, int b) { return a < b;}intmain() { int a[3]; scanf("%d %d %d", &a[0], &a[1], &a[2]); sort(a, a + 3, cmp); printf("%d->%d->%d\n", a[0], a[1], a[2]); return 0;}
(2)
#include#include using namespace std;intmain() { int a, b, c; scanf("%d %d %d", &a, &b, &c); if( a > b ) { swap(a, b); } if( a > c ) { swap(a, c); } if( b > c ) { swap(b, c); } printf("%d->%d->%d\n", a, b, c); return 0;}
(3)
#includeintmain() { int a, b, c; scanf("%d %d %d", &a, &b, &c); if( a < b ) { if( b < c ) { printf("%d->%d->%d\n", a, b, c); } else { if( a < c ) { printf("%d->%d->%d\n", a, c, b); } else { printf("%d->%d->%d\n", c, a, b); } } } else { if( a < c ) { printf("%d->%d->%d\n", b, a, c); } else { if( b < c ) { printf("%d->%d->%d\n", b, c, a); } else { printf("%d->%d->%d\n", c, b, a); } } } return 0;}
转载地址:http://jpkxi.baihongyu.com/