1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-27 08:26:20 +00:00
202401-programming-assignments/【额外练习】选择结构/7-31 选择-猜数字游戏.c

30 lines
586 B
C
Raw Normal View History

2024-10-30 15:00:18 +00:00
#include <stdio.h>
int main() {
int total, andy, ban;
scanf("%d%d%d", &total, &andy, &ban);
int andyDiff = total - andy;
int banDiff = total - ban;
if (andyDiff < 0) andyDiff = -andyDiff;
if (banDiff < 0) banDiff = -banDiff;
if (andyDiff == banDiff) {
if (andy < ban) {
printf("Andy\n");
} else if (andy == ban) {
printf("Peace\n");
} else {
printf("Ban\n");
}
} else if (andyDiff < banDiff) {
printf("Andy\n");
} else {
printf("Ban\n");
}
return 0;
}