2021-12-07 19:45

# C语言编程问题求解答

K is the counterfeit coin and it is light.

K is the counterfeit coin and it is heavy.

1
ABCD EFGH even
ABCI EFJK up
ABIJ EFGH even

K is the counterfeit coin and it is light.

K is the counterfeit coin and it is light.

• 写回答
• 好问题 提建议
• 追加酬金
• 关注问题
• 邀请回答

#### 1条回答默认 最新

• panfei625 2021-12-07 19:53
最佳回答
``````
#include <cstdio>
#include <cstring>

char Left[3][8], Right[3][8], Result[3][8];
int status[12];

bool test(){
int left, right;
for(int i = 0; i < 3; i++){
left = right = 0;
for(int j = 0; j < 6 && Left[i][j] != 0; j ++){
left += status[Left[i][j] - 'A'];
right += status[Right[i][j] - 'A'];
}
if(left > right && Result[i][0] != 'u')
return false;
if(left < right && Result[i][0] != 'd')
return false;
if(left == right && Result[i][0] != 'e')
return false;
}
return true;
}

int main(){
int n;
scanf("%d", &n);
while(n--){
for(int i = 0; i < 3; i++){
scanf("%s%s%s", Left[i], Right[i], Result[i]);
}
memset(status, 0, sizeof(status));
int i;
for(i = 0; i < 12; i++){
status[i] = -1;
if(test())
break;
status[i] = 1;
if(test())
break;
status[i]= 0;
}
printf("%c is the counterfeit coin and it is %s.\n", i + 'A', status[i] > 0 ? "heavy" : "light");
}
return 0;
}
``````
评论
解决 无用 1
打赏 举报