很简单,没什么要注意的,就是我的代码冗余了点,其实甲乙胜负以及平局都用石头剪刀布的数目表示就好,这位大神的代码极其简洁PAT Basic 1018. 锤子剪刀布 (20)(C语言实现)
以下是我的
#include <stdio.h>
char max(int b, int c, int j)
{
if(b >= c && b >= j)
return 'B';
else if(c > b && c >= j)
return 'C';
return 'J';
}
int main()
{
int N, jias = 0, jiaf = 0, yis = 0, yif = 0, count = 0;
int jj = 0, jc = 0, jb = 0;
int yj = 0, yc = 0, yb = 0;
scanf("%d", &N);
while(N--)
{
while(getchar() != '\n');
char j, y;
scanf("%c %c", &j, &y);
if(j == 'J' && y == 'B')
{
jias++;
yif++;
jj++;
}
else if(j == 'C' && y == 'J')
{
jias++;
yif++;
jc++;
}
else if(j == 'B' && y == 'C')
{
jias++;
yif++;
jb++;
}
else if(j == 'C' && y == 'B')
{
jiaf++;
yis++;
yb++;
}
else if(j == 'J' && y == 'C')
{
jiaf++;
yis++;
yc++;
}
else if(j == 'B' && y == 'J')
{
jiaf++;
yis++;
yj++;
}
else
count++;
}
printf("%d %d %d\n",jias, count, jiaf);
printf("%d %d %d\n",yis, count, yif);
printf("%c %c",max(jb, jc, jj), max(yb, yc, yj));
return 0;
}