PAT | 1018 hammer scissors cloth (20 points)

Everyone should be able to play the game of "hammer, scissors, cloth": two people give gestures at the same time, and the rules of winning and losing are shown in the figure:
FigCJB.jpg

Now give the record of the confrontation between the two, please count the number of wins, draws, and losses of the two sides, and give the best chance of winning by which gesture the two sides make.

Input format:

Enter the first line to give a positive integer N (≤10 5 ), which is the number of times the two sides have fought. Then N lines, each line gives information about a confrontation, that is, the gestures given by both parties at the same time. C stands for "hammer", J stands for "scissors", B stands for "cloth", the first letter represents Party A, the second represents Party B, and there is a space in between.

Output format:

The first and second lines of the output give the number of wins, draws, and losses of A and B respectively, and the numbers are separated by a space. Line 3 gives two letters, representing the gestures that A and B have won the most times, with a space in between. If the solution is not unique, the smallest solution in alphabetical order is output.

Input sample:

10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J

Sample output:

5 3 2
2 3 5
B B
#include <iostream>
using namespace std;

int main()
{
    
    
    char j,y,hand[4]="BCJ";
    int n;
    int jia[3]={
    
    0},yi[3]={
    
    0};
    int jia_hand[3]={
    
    0},yi_hand[3]={
    
    0};
    cin >>n;
    getchar();
    for(int i=0;i<n;i++){
    
    
        cin >>j>>y;
        if(j==y){
    
    
            jia[1]++;
            yi[1]++;
        }
        if(j=='B'&&y=='C'){
    
    
            jia[0]++;
            jia_hand[0]++;
            yi[2]++;
        }
        if(j=='B'&&y=='J'){
    
    
            yi[0]++;
            yi_hand[2]++;
            jia[2]++;
        }
        if(j=='C'&&y=='B'){
    
    
            yi[0]++;
            yi_hand[0]++;
            jia[2]++;
        }
        if(j=='C'&&y=='J'){
    
    
            jia[0]++;
            jia_hand[1]++;
            yi[2]++;
        }
        if(j=='J'&&y=='C'){
    
    
            yi[0]++;
            yi_hand[1]++;
            jia[2]++;
        }
        if(j=='J'&&y=='B'){
    
    
            jia[0]++;
            jia_hand[2]++;
            yi[2]++;
        }
    }
    cout <<jia[0]<<" "<<jia[1]<<" "<<jia[2]<<endl;
    cout <<yi[0]<<" "<<yi[1]<<" "<<yi[2]<<endl;  
    int max_yi=yi_hand[0],max_jia=jia_hand[0];
    int index_yi=0,index_jia=0;
    for(int i=1;i<3;i++){
    
    
        if(max_yi<yi_hand[i]){
    
    
            max_yi=yi_hand[i];
            index_yi=i;
        }
        if(max_jia<jia_hand[i]){
    
    
            max_jia=jia_hand[i];
            index_jia=i;
        }
    }
    cout <<hand[index_jia]<<" "<<hand[index_yi];
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_44888152/article/details/108641183