Hammer 1018 scissors (20 minutes)
We should be able to play "hammer and scissors" game: they both give gesture, as shown in Figure outcome of the rules:
Now given the two men clash records, statistics of both wins, flat, negative number, and the two sides are what give the greatest chance of winning gesture.
Input format:
Enter line 1 gives a positive integer N (≤10 ^ 5), i.e., both the number of confrontation. Then N rows, each row gives information confrontation, i.e., the gesture and B sides at the same time is given. C stands for "hammer", the representative J "scissors", B stands for "cloth", the first letter represents a party, on behalf of the second party, there is an intermediate space.
Output Format:
output the first and second lines are given A, B wins, flat, negative number, separated by an inter-digital space. Line 3 shows two letters represent A, B wins the highest number of gestures, there is an intermediate space. If the solution is not unique, the minimum solution alphabetically output.
Sample input:
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
Sample output:
5 3 2
2 3 5
B B
**
Write super long, super long changed, writing sucks, long and boring ...
Finally I found it a mistake, added the little getchar () on line 60;
As to why you want to add this one, please move https://blog.csdn.net/weixin_44562957/article/details/104117402
#include <stdio.h>
int judge(char x,char y) //判断输赢
{
if(x=='C')
{
if(y=='C')
return 0;
else if(y=='J')
return 1;
else if(y=='B')
return 2;
}
if(x=='J')
{
if(y=='C')
return 2;
else if(y=='J')
return 0;
else if(y=='B')
return 1;
}
if(x=='B')
{
if(y=='C')
return 1;
else if(y=='J')
return 2;
else if(y=='B')
return 0;
}
}
int aa(int c,int j,int b) //判断出哪个获胜最多并输出
{
if(b>=c)
{
if(b>=j)
printf("B");
else
printf("J");
}
else
{
if(c>=j)
printf("C");
else
printf("J");
}
return 0;
}
int main()
{
int n;
scanf("%d",&n);
char a,b;
int jw,jl,je,yw,yl,ye,jc,jj,jb,yc,yj,yb;
jw=jl=je=yw=yl=ye=jc=jj=jb=yc=yj=yb=0;
for(int i=0;i<n;i++)
{
getchar();
scanf("%c %c",&a,&b);
if(judge(a,b)==0) //平局
{
je++;
ye++;
}
if(judge(a,b)==1) //甲赢
{
jw++;
yl++;
if(a=='C')
jc++;
else if(a=='J')
jj++;
else if(a=='B')
jb++;
}
if(judge(a,b)==2) //甲输
{
jl++;
yw++;
if(b=='C')
yc++;
else if(b=='J')
yj++;
else if(b=='B')
yb++;
}
}
printf("%d %d %d\n",jw,je,jl);
printf("%d %d %d\n",yw,ye,yl);
aa(jc,jj,jb);
printf(" ");
aa(yc,yj,yb);
printf("\n");
return 0;
}
/*
写的超级长,改了超级久,写的很烂,又臭又长...
最后发现就一个错误,在第60行少加了一句getchar();
至于为什么要加这一句,请移步https://blog.csdn.net/weixin_44562957/article/details/104117402
*/