1018 hammer scissors cloth (20 points)

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

Now the record of the confrontation between the two is given. Please count the number of wins, draws and losses of both sides, and give what gestures the two sides make respectively, which has the greatest chance of winning.

Input format:

Input line 1 gives a positive integer   N (≤ 105), that is, the number of exchanges between the two sides. subsequently   N   Line, each line gives the information of a confrontation, that is, the gesture given by both Party A and Party B at the same time. C   Stands for "hammer", J   Stands for "scissors", B   Represents "cloth", the first letter represents Party A, the second represents Party B, and there is a space in the middle.

Output format:

The output lines 1 and 2 give the winning, equalizing and negative times of a and B respectively, and the numbers are separated by a space. The third line gives two letters, respectively representing the gesture with the most winning times of a and B, with a space in the middle. If the solution is not unique, the solution with the smallest alphabetical order is output.

Input example:

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

No blank lines at the end

Output example:

5 3 2
2 3 5
B B

No blank lines at the end

#include <stdio.h>
#pragma warning (disable:4996)
int main() {
	/*1.Cyclic input
	2.4 Each array judges the record information through conditions
	,output*/
	int bookjia[3] = { 0 }, bookyi[3] = { 0 };
	int book1[500] = { 0 }, book2[500] = { 0 };
	int N;
	char jia, yi;
	scanf("%d", &N);
	for (int cnt = 0; cnt < N; cnt++) {
		getchar();
		scanf("%c %c", &jia, &yi);
		
		if (jia == 'C' && yi == 'J') {
			bookjia[0]++;
			bookyi[2]++;
			book1[(int)(jia)]++;
		}
		else if (jia == 'C' && yi == 'C') {
			bookjia[1]++;
			bookyi[1]++;
		}
		else if (jia == 'C' && yi == 'B') {
			bookjia[2]++;
			bookyi[0]++;
			book2[(int)(yi)]++;
		}
		else if (jia == 'J' && yi == 'C') {
			bookjia[2]++;
			bookyi[0]++;
			book2[(int)(yi)]++;
		}
		else if (jia == 'J' && yi == 'J') {
			bookjia[1]++;
			bookyi[1]++;
		}
		else if (jia == 'J' && yi == 'B') {
			bookjia[0]++;
			bookyi[2]++;
			book1[(int)(jia)]++;
		}
		else if (jia == 'B' && yi == 'C') {
			bookjia[0]++;
			bookyi[2]++;
			book1[(int)(jia)]++;
		}
		else if (jia == 'B' && yi == 'B') {
			bookjia[1]++;
			bookyi[1]++;
		}
		else if (jia == 'B' && yi == 'J') {
			bookjia[2]++;
			bookyi[0]++;
			book2[(int)(yi)]++;
		}
		//printf("********\n");
		

	}
	printf("%d %d %d\n", bookjia[0], bookjia[1], bookjia[2]);
	printf("%d %d %d\n", bookyi[0], bookyi[1], bookyi[2]);
	int max = (int)'B';
	for (int cnt = 0; cnt < 500; cnt++) {
		if (book1[cnt] > book1[max]) {
			max = cnt;
		}
	}
	printf("%c ", max);
	max = (int)'B';
	for (int cnt = 0; cnt < 500; cnt++) {
		if (book2[cnt] > book2[max]) {
			max = cnt;
		}
	}
	printf("%c", max);
	
	return 0;
}

  In fact, this question is not difficult. It's OK to write conditional judgment madly;

The pit I stepped on: 1. Without using getchar(), I forgot to consider the influence of newline characters, because% c will input a single character in all buffers, which means that it can absorb newline characters. I forgot that there is also a newline character in the first line and there is a newline character after each line input. We need to absorb each newline character first, Before you can enter the absorption link of scanf;

2. Find out what the two most winning gestures are. I directly write a simple bucket here, because considering the problem of alphabetic order, I don't need to make this judgment with the bucket. Then I wrote the condition of the bucket wrong. Here, pay attention to the comparison of conditions in the process of circular comparison. Here, I compare the values in the array, I made a mistake at first. I made a direct comparison between the elements in the array and max, which led to my mistake

Keywords: C

Added by grim1208 on Sat, 27 Nov 2021 04:42:07 +0200