BUPT-homework/pset2/1-basketball.c
2021-09-28 19:52:33 +08:00

56 lines
940 B
C

#include <stdio.h>
int main(void) {
// initialize variables
int a, b;
scanf("%i %i", &a, &b);
// case 1: one team has reached 21 points. and less than 22 points
if (a >= 21 && a <= 22) {
if (b < 21) {
printf("A win");
return 0;
} else {
printf("error");
return 0;
}
}
if (b >= 21 && b <= 22) {
if (a < 21) {
printf("B win");
return 0;
} else {
printf("error");
return 0;
}
}
// case 2: one team has more points but less than 21 points.
if (a < 21 && b < 21) {
if (a > b) {
printf("A win");
return 0;
} else if (a < b) {
printf("B win");
return 0;
}
}
// case 3: one team has more points than 22
if (a > 22 || b > 22) {
printf("error");
return 0;
}
// case 4: scores are equal
if (a == b) {
if (a < 21 && b < 21) {
printf("no result");
return 0;
}
}
return 0;
}