Pat_hammerscissors

 

Title Description

Everyone should play the game of "hammer, scissors and cloth":

Here is the record of the fight between the two. Please count the number of wins, evenings and defeats of both sides, and give the most successful hand gestures of both sides.

 

Enter a description:

Enter the first line to give a positive integer N (< 105), that is, the number of times the two sides meet. Then N lines, each line gives the information of a confrontation, that is, the gestures given by both parties at the same time. C for "hammer", J for "scissors", generation B

The first letter of the table "cloth" represents Party A, the second represents Party B, and there is a space in the middle.


 

Output Description:

The first and second lines of the output show the win, level and negative times of a and B respectively, and the numbers are separated by a space. The third line gives two letters, representing the gesture with the most winning times of a and B respectively, with a space in the middle. If the solution is not unique

1, The output is the smallest solution in alphabetical 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

Algorithm implementation:

#include <stdio.h>

int main()
{
    int i,n,win=0,draw=0,loss=0,c1=0,j1=0,b1=0,c2=0,j2=0,b2=0;
    char a,b;
    scanf("%d",&n);
    
    for (i=0; i<n; i++) {
        getchar();
        scanf("%c %c",&a,&b);
        
        if (a==b) {
            draw++;
        } else if ((a=='C'&&b=='J')||(a=='J'&&b=='B')||(a=='B'&&b=='C')) {
            win++;
            
            if (a=='C') {
                c1++;
            }
            if (a=='J') {
                j1++;
            }
            if (a=='B') {
                b1++;
            }
        } else {
            loss++;
            if (b=='C') {
                c2++;
            }
            if (b=='J') {
                j2++;
            }
            if (b=='B') {
                b2++;
            }
        }
    }
    printf("%d %d %d\n%d %d %d\n",win,draw,loss,loss,draw,win);
    if (b1>=c1&&b1>=j1) {
        printf("B ");
        
    } else if (c1>=b1&&c1>=j1) {
        printf("C ");
    } else if (j1>=c1&&j1>=b1) {
        printf("J ");
        
    } else {
        printf("B ");
    }
    if (b2>=c2&&b2>=j2) {
        printf("B");
    } else if (c2>=b2&&c2>=j2) {
        printf("C");
        
    } else if (j2>=c2&&j2>=b2) {
        printf("J");
    } else {
        printf("B");
    }
    
    return 0;
}

 

Posted by eashton123 on Mon, 06 Jan 2020 14:15:14 -0800