int N;
int C_jia; /* 如果甲赢且甲等于C,给C_jia自增1 以下类似 */
int J_jia;
int C_yi;
int J_yi;
int jia_win;
int pingju;
void read();
void print_result();
char max_cjb(int c, int j, int b);
/****************************** 读入 ***********************************/
void read(){
char jia, yi;
int i;
scanf("%d", &N);
for(i = 0; i < N; ++i){
scanf(" %c %c", &jia, &yi);
if(jia == 'C'){
if(yi == 'J'){ /* 甲赢 */
++jia_win;
++C_jia;
}else if(yi == 'B') /* 乙赢 */
;
else
++pingju;
}else if(jia == 'J'){
if(yi == 'B'){ /* 甲赢 */
++jia_win;
++J_jia;
}else if(yi == 'C') /* 乙赢 */
++C_yi;
else
++pingju;
}else{//jia == 'B'
if(yi == 'C') /* 甲赢 */
++jia_win;
else if(yi == 'J') /* 乙赢 */
++J_yi;
else
++pingju;
}
}
}
/***************************** 输出结果 *********************************/
void print_result(){
char max;
int yi_win;
yi_win = N - jia_win - pingju;
printf("%d %d %d\n", jia_win, pingju, yi_win);
printf("%d %d %d\n", yi_win, pingju, jia_win);
max = max_cjb(C_jia, J_jia, jia_win-C_jia-J_jia);
printf("%c ", max);
max = max_cjb(C_yi, J_yi, (yi_win-C_yi-J_yi));
printf("%c", max);
}
/************************ 求得cjb中最大值所对应的字符串 ****************/
char max_cjb(int c, int j, int b){
char max;
int max_cj;
if(c >= j){
max_cj = c;
max = 'C';
}else{
max_cj = j;
max = 'J';
}
if(b >= max_cj)
max = 'B';
return max;
}
int main(){
N = 0;
jia_win = pingju = 0;
J_jia = C_jia = 0;
J_yi = C_yi = 0;
read();
print_result();
}
【PAT B1018】锤子剪刀布 (C语言)
最新推荐文章于 2021-08-05 20:17:56 发布