1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 14:36:19 +00:00
202401-programming-assignments/【实践课内】3.选择结构2/7-2 21选择-我们是冠军.c

53 lines
973 B
C
Raw Normal View History

2024-10-23 02:25:07 +00:00
#include <stdio.h>
int main() {
int type;
double s1, s2, s3;
scanf("%d%lf%lf%lf", &type, &s1, &s2, &s3);
if (type == 0) { // 赛跑,从低到高排序
if (s1 > s2) {
double temp = s1;
s1 = s2;
s2 = temp;
}
if (s1 > s3) {
double temp = s1;
s1 = s3;
s3 = temp;
}
if (s2 > s3) {
double temp = s2;
s2 = s3;
s3 = temp;
}
printf("%.2lf %.2lf %.2lf\n", s1, s2, s3);
} else { // type == 1
if (s1 < s2) {
double temp = s1;
s1 = s2;
s2 = temp;
}
if (s1 < s3) {
double temp = s1;
s1 = s3;
s3 = temp;
}
if (s2 < s3) {
double temp = s2;
s2 = s3;
s3 = temp;
}
printf("%.2lf %.2lf %.2lf\n", s1, s2, s3);
}
return 0;
}