PAT - Grade B 1018 Hammer Scissors Cloth

1018. Hammer, scissors, cloth(20)

time limit
100 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
CHEN, Yue

Everyone should play the game of "hammer, scissors and paper": two people give gestures at the same time, and the rules of winning and losing are shown in the figure:

Now give the record of the confrontation between the two, please count the number of wins, draws, and losses of the two sides, and give the gestures of the two sides that have the best chance of winning.

Input format:

Enter line 1 to give a positive integer N (<=10 5 ), the number of times the two sides fought. Then there are N lines, each line gives the information of a confrontation, that is, the gestures given by both A and B at the same time. C stands for "hammer", J stands for "scissors", B stands for "cloth", the first letter represents Party A, the second represents Party B, and there is a space in the middle.

Output format:

The first and second lines of the output give the number of wins, draws, and losses of A and B, respectively, and the numbers are separated by a space. Line 3 gives two letters, representing the gestures with the most wins by A and B, with a space in between. If the solutions are not unique, the alphabetically smallest solution is output.

Input sample:
10
CJ
J B
C B
B B
B C
C C
C B
J B
B C
not a word
Sample output:
5 3 2
2 3 5
B B

Note: If one side has not won, then output B. I wasted half an hour on this issue. I don't know why it's wrong.

#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	freopen("input.txt", "r", stdin);
	int n, jia[6], yi[6]; // BCJ
	char ans[3] = {'J', 'C', 'B'};
	scanf("%d\n", &n);
	memset(jia, 0, sizeof(jia));
	memset(yi, 0, sizeof(yi));
	for(int i = 0; i < n; i++){
		char a, b;
		scanf("%c %c\n", &a ,&b);
//		printf("%c %c\n", a ,b);
		if(a == b) jia[1]++, yi[1]++;
		else if(a == 'B'){
			if(b == 'C') jia[0]++, yi[2]++, jia[3]++;
			else jia[2]++, yi[0]++, yi[5]++;
		}else if(a == 'C'){
			if(b == 'J') jia[0]++, yi[2]++, jia[4]++;
			else jia[2]++, yi[0]++, yi[3]++;
		}else if(a == 'J'){
			if(b == 'B') jia[0]++, yi[2]++, jia[5]++;
			else jia[2]++, yi[0]++, yi[4]++;
		}
	}
	printf("%d %d %d\n", jia[0], jia[1], jia[2]);
	printf("%d %d %d\n", yi[0], yi[1], yi[2]);
	int max_j = 0, max_y = 0;
	char ans_j = 'B', ans_y = 'B';
	for(int i = 0; i < 3; i++){
		
		if(jia[3 + i] > max_j) max_j = jia[3 + i], ans_j = ans[2 - i];
		if(yi[3 + i] > max_y) max_y = yi[3 + i], ans_y = ans[2 - i];
	}
	printf("%c %c", ans_j, ans_y);
	return 0;
}



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325757012&siteId=291194637