PAT 1018. 锤子剪刀布 (20)

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。

输入格式:

输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。

输出格式:

输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。

输入样例:

10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J

输出样例:

5 3 2
2 3 5
B B

这次写的不是很精简
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 #include<stdlib.h>
 5 int main(){
 6     int n;
 7     int J1=0,C1=0,B1=0;
 8     int J2=0,C2=0,B2=0;
 9     char temp,temp2;
10     int a1=0,a2=0,a3=0;
11     int b1=0,b2=0,b3=0;
12     int k1=0,k2=0;
13     scanf("%d",&n);
14     getchar();
15     for(int i=0;i<n;i++){
16         scanf("%c %c",&temp,&temp2);
17         getchar();
18         if(temp=='J'&&temp2=='B'){
19             a1++;
20             b3++;
21             J1++;
22         }else if(temp=='J'&&temp2=='C'){
23             a3++;
24             b1++;
25             C2++;
26         }else if(temp=='J'&&temp2=='J'){
27             a2++;
28             b2++;
29         }else if(temp=='C'&&temp2=='J'){
30             a1++;
31             b3++;
32             C1++;
33         }else if(temp=='C'&&temp2=='B'){
34             a3++;
35             b1++;
36             B2++;
37         }else if(temp=='C'&&temp2=='C'){
38             a2++;
39             b2++;
40         }else if(temp=='B'&&temp2=='J'){
41             a3++;
42             b1++;
43             J2++;
44         }else if(temp=='B'&&temp2=='C'){
45             a1++;
46             b3++;
47             B1++;
48         }else if(temp=='B'&&temp2=='B'){
49             a2++;
50             b2++;
51         }
52     }
53     printf("%d %d %d
",a1,a2,a3);
54     printf("%d %d %d
",b1,b2,b3);
55     if(B1>=C1&&B1>=J1)
56         printf("B ");
57     else if(C1>=J1)
58         printf("C ");
59     else
60         printf("J ");
61     if(B2>=C2&&B2>=J2)
62         printf("B");
63     else if(C2>=J2)
64         printf("C");
65     else
66         printf("J");
67     
68 }
原文地址:https://www.cnblogs.com/lolybj/p/6186333.html