1018. Hammer and Scissors cloth (20)
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
#include <iostream>#include<iomanip>#include<math.h>#include<stdio.h>#include<string>using namespacestd;intMain () {intN; CIN>>N; intjia_s[3] = {0 }; intjia_odds[3] = {0}, yi_odds[3] = {0};//number of gesture wins order B C J Charjia_ss[3] = {'B','C','J'}, yi_ss[3] = {'B','C','J' }; for(inti =0; I < n; i++) { CharJia, Yi; CIN>> Jia >>Yi; Switch(Jia) { Case'C': { if(Yi = ='C') {jia_s[1] ++; } if(Yi = ='J') {jia_s[0]++; jia_odds[1]++; } if(Yi = ='B') {jia_s[2]++; yi_odds[0]++; } Break; } Case'J': { if(Yi = ='J') {jia_s[1] ++; } if(Yi = ='B') {jia_s[0]++; jia_odds[2]++; } if(Yi = ='C') {jia_s[2]++; yi_odds[1]++; } Break; } Case'B': { if(Yi = ='B') {jia_s[1] ++; } if(Yi = ='C') {jia_s[0]++; jia_odds[0]++; } if(Yi = ='J') {jia_s[2]++; yi_odds[2]++; } Break; } default: Break; }} cout<< jia_s[0] <<" "<< jia_s[1] <<" "<<jia_s[2] <<Endl; cout<< jia_s[2] <<" "<< jia_s[1] <<" "<< jia_s[0] <<Endl; if((jia_odds[0] >= jia_odds[1]) && (jia_odds[0] >= jia_odds[2])) cout<<"B"; Else if(jia_odds[1] >= jia_odds[2]) cout<<"C"; Elsecout<<"J"; if((yi_odds[0] >= yi_odds[1]) && (yi_odds[0] >= yi_odds[2])) cout<<"B"; Else if(yi_odds[1] >= yi_odds[2]) cout<<"C"; Elsecout<<"J"; System ("Pause"); return 0;}
1018. Hammer and Scissors cloth (20)