[PAT] 1018 锤子剪刀布 (20 分)
PAT (Basic Level) Practice （中文） 1018 锤子剪刀布 (20 分) https:/...

11
2019/09

# [PAT] 1018 锤子剪刀布 (20 分)

PAT (Basic Level) Practice （中文） 1018 锤子剪刀布 (20 分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805304020025344

## wa18分

package PAT.BasicLevel;

import java.util.Scanner;

public class _1018_锤子剪刀布 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int[] A = new int[3];//胜 平 败 //甲

int[] winA = new int[3];//b c j//甲
int[] winB = new int[3];//b c j//乙
char[] sign={'B','C','J'};
while (n-- > 0) {
char a = cin.next().charAt(0);

char b = cin.next().charAt(0);
switch (a) {
case 'B'://布
if (b == a) {//平局
A[1]++;
} else if (b == 'J') {A[2]++;winB[2]++;}//输了
else {
A[0]++;
winA[0]++;
}//赢了
break;
case 'J':
if (b == a) {//平局
A[1]++;
} else if (b == 'C') {A[2]++;winB[1]++;}//输了
else {
A[0]++;
winA[2]++;
}//赢了
break;
case 'C':
if (b == a) {//平局
A[1]++;
} else if (b == 'B') {A[2]++;winB[0]++;}//输了
else {
A[0]++;
winA[1]++;
}//赢了
break;
}
}
int max=winA[0],tA=0,tB=0;
for (int i = 1; i <winA.length ; i++) {
if(winA[i]>max){
max=winA[i];
tA=i;
}
}
max=winB[0];
for (int i = 1; i <winB.length ; i++) {
if(winB[i]>max){
max=winB[i];
tB=i;
}
}
System.out.println(A[0] + " " + A[1] + " " + A[2]);
System.out.println(A[2] + " " + A[1] + " " + A[0]);
System.out.println(sign[tA]+" "+sign[tB]);
}
}

百度已收录

Last modification：September 11th, 2019 at 10:34 pm