Title Link: http://www.patest.cn/contests/pat-b-practise/1018
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 the 1th line to give the positive integer n (<=105), which 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:
#include <cstdio>int main () {int n; int a1=0,a2=0,a3=0;//A win, draw, B win int aj=0,ac=0,ab=0;//out what way to win multiple int bj=0,bc=0,bb=0; Char x,y,blank;scanf ("%d", &n); for (int i = 0; i < n; i++) {GetChar (); scanf ("%c%*c%c", &x,&y); if ((x== ' C ') && (y== ' J ')) {a1++; ac++; continue;} if (x== ' J ') && (y== ' B ')) {a1++; aj++; continue;} if ((x== ' B ') && (y== ' C ')) {a1++; ab++; continue;} if ((x== ' C ') && (y== ' C ')) {a2++; continue;} if (x== ' J ') && (y== ' J ')) {a2++; continue;} if ((x== ' B ') && (y== ' B ')) {a2++; continue;} if ((x== ' C ') && (y== ' B ')) {a3++; bb++; continue;} if (x== ' B ') && (y== ' J ')) {a3++; bj++; continue;} if (x== ' J ') && (y== ' C ')) {a3++; bc++; continue;} }printf ("%d%d%d\n", a1,a2,a3);p rintf ("%d%d%d\n", A3,A2,A1); if ((AB>=AC) && (Ab>=aj)) printf ("B"); else if (AC >= AJ) printf ("C"); else printf ("J"); if ((bb>=BC) && (BB>=BJ)) printf ("b\n"); else if (BC>=BJ) printf ("c\n"); else printf ("j\n"); return 0;}
1018. Hammer and Scissors Cloth (20) (Math ah Zju_pat)