Problem description
Everyone should play "Hammer and Scissors Cloth" game: two people at the same time give gestures, the rule of victory:
Now give a record of the confrontation between two people, please count the wins, flat, negative number of both sides, and give the two sides what gesture of the greatest odds.
Input format:
Enter line 1th to give the positive integer n (<=105), that is, the number of times the two sides clash. Then n lines, each row gives the information of a confrontation, that is, a, b both sides of the gesture given at the same time. C for "Hammer", J for "Scissors", B for "cloth", 1th letter for party A, 2nd for party B, 1 spaces in the middle.
Output format:
Output 1th, 2 respectively give a, B wins, flat, negative times, the number between 1 spaces separated. The 3rd line gives two letters, representing the most winning gestures of A and b, with 1 spaces in the middle. If the solution is not unique, the solution with the smallest alphabetic order is output.
Input Sample:
10C JJ BC bb bb cc cc BJ BB CJ J
Sample output:
5 3 3 5B B
The code is as follows:
1#include <cstdio>2 3 intChangeCharc) {4 if(c = ='B')return 0;5 if(c = ='C')return 1;6 if(c = ='J')return 2;7 }8 intMain ()9 {Ten intN; One Charmp[3]={'B','C','J'}; Ascanf"%d",&n); - inttime_a[3] = {0},time_b[3] = {0}; - inthand_a[3] = {0},hand_b[3] = {0}; the Charc1,c2; - intK1,k2; - for(inti =0; I < n;i++){ - GetChar (); +scanf"%c%c", &C1, &C2); -K1 =Change (C1); +K2 =Change (C2); A if((K1 +1) %3==K2) { attime_a[0]++; -time_b[2]++; -hand_a[k1]++; -}Else if(K1 = =K2) { -time_a[1]++; -time_b[1]++; in}Else { -time_a[2]++; totime_b[0]++; +hand_b[k2]++; - } the } *printf"%d%d%d\n", time_a[0],time_a[1],time_a[2]); $printf"%d%d%d\n", time_b[0],time_b[1],time_b[2]);Panax Notoginseng intID1 =0, Id2 =0; - for(intI=0; I <3; i++){ the if(Hand_a[i] > hand_a[id1]) id1 =i; + if(Hand_b[i] > Hand_b[id2]) id2 =i; A } theprintf"%c%c\n", Mp[id1], Mp[id2]); + - return 0; $}
Thinking Analysis:
Record the winning and losing level separately. There is no special pit waiting for everyone to jump ~
pat_1018 Hammer and scissors cloth