Links: http://www.nowcoder.com/pat/6/problem/4044
Title Description
Everyone should play "Hammer and Scissors cloth" game:
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 Description:
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 Stands for "Hammer", J for "Scissors", and b generation
Table "Cloth", the 1th letter represents party A, the 2nd represents party B, there are 1 spaces in the middle.
Output Description:
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 the only
One, the output is sorted by the smallest alphabetic order.
Input Example:
10
C J
J B
C B
b b
B C
C C
C B
J B
B C
J J
Output Example:
5 3 2
2 3 5
b b
#include"iostream"#include<iomanip>#include<string.h>#include<string>#include<vector>#include<cmath>#include<cctype>#include<algorithm>using namespacestd;intT;intP1, F1;vector<Char>W1;vector<Char>W2;CharCount (vector<Char>Charvec) { intnum[3] = {0}; for(intI=0; I<charvec.size (); ++i) {if(Charvec[i] = ='B') { ++num[0]; } Else { if(Charvec[i] = ='C') { ++num[1]; } Else { ++num[2]; } } } inttmp=0, pos=0; for(intI=0; i<3; ++i) {if(Num[i] >tmp) {tmp=Num[i]; POS=i; } } if(pos = =0) { return 'B'; } Else { if(pos = =1) { return 'C'; } Else { return 'J'; } }}voidsolve () {P1= F1 =0; CIN>>T; for(intI=0; i<t; ++i) {CharC1, C2; CIN>>C1 >>C2; if(C1 = ='C') { if(C2 = ='C') { ++P1; } Else { if(C2 = ='B') {w2.push_back (C2); ++F1; } Else{w1.push_back (C1); } } } Else { if(C1 = ='B') { if(C2 = ='B') { ++P1; } Else { if(C2 = ='J') {w2.push_back (C2); ++F1; } Else{w1.push_back (C1); } } } Else { if(C2 = ='J') { ++P1; } Else { if(C2 = ='C') {w2.push_back (C2); ++F1; } Else{w1.push_back (C1); } }}} cout<<w1.size () <<" "<<P1 <<" "<<F1 <<Endl; cout<<w2.size () <<" "<<P1 <<" "<<w1.size () <<Endl; cout<<count (W1) <<" "<<count (W2) <<Endl;}intMain () {solve (); return 0;}
Scissors and stone cloth