1018 Hammer and scissors cloth (20) (20 points)
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 (<=10^5^), 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 22 3 5B B
#include <iostream>#include<stdlib.h>using namespacestd;intFindNum (CharAChar*code) { for(inti =0; I <3; i++) { if(Code[i] = =a)returni; }}intMain () {intN//a few rounds of games Charcode[3] = {'B','C','J'};//number of each hand type intchess[3][3] = {{0,1, -1}, {-1,0,1}, {1, -1,0}};//the winning and losing situation of a in each case intresult[2][3];//record the number of a-B wins flat negative intwin[2][3];//record the number of hand shapes in a round won by a B for(inti =0; I <2; i++) { for(intj =0; J <3; J + +) {Result[i][j]=0; WIN[I][J]=0; }} cin>>N; while(n--) { CharA, B; CIN>> a >>b; intm =FindNum (A, code); intn =FindNum (b, code); if(Chess[m][n] = =1) {result[0][0]++; result[1][2]++; win[0][m]++; } Else if(Chess[m][n] = =0) {result[0][1]++; result[1][1]++; } Else{result[0][2]++; result[1][0]++; win[1][n]++; } } /*outputs the number of times each of the results of each side*/ for(inti =0; I <2; i++) { for(intj =0; J <3; J + +) {cout<<Result[i][j]; if(J = =2) cout<<Endl; Elsecout<<" "; } } /*find the hand that wins the most times*/ intx[2] = {0,0 }; for(inti =0; I <2; i++) { intMax =0; for(intj =0; J <3; J + +) { if(Win[i][j] >max) {Max=Win[i][j]; X[i]=J; } }} cout<< code[x[0]] <<" "<< code[x[1]] <<Endl; System ("Pause"); return 0;}
Pat B 1018. Hammer and Scissors Cloth (20) (20 min)