1018 hammer scissors (20 points)

Keywords: PHP

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

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.

Input format:

Enter line 1 to give a positive integer < N (≤), that is, the number of times the two sides meet. Then line N, each line gives the information of a confrontation, that is, the gestures given by both parties at the same time. C represents "hammer", J represents "scissors", B represents "cloth", the first letter represents Party A, the second represents Party B, and there is a space in the middle.

Output format:

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, the solution with the smallest alphabetical order is output.

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<stdio.h>
#include<string.h>

struct peo {
    int j ; 
    int b;
    int c;
    int win;

}pa, pb;

int main() {
    pa.b = pa.c = pa.j = pa.win = 0;
    pb.b = pb.c = pb.j = pb.win = 0;
    int n;
    char ca,cb;
    scanf("%d", &n);
    int i;
    for (i = 0; i < n; i++) {
        scanf(" %c %c", &ca, &cb);
        if (ca == 'J') {
            if (cb == 'B')pa.j++;
            if (cb == 'C')pb.c++;
        }
        if (ca == 'B') {
            if (cb == 'C')pa.b++;
            if (cb == 'J')pb.j++;
        }
        if (ca == 'C') {
            if (cb == 'J')pa.c++;
            if (cb == 'B')pb.b++;
        }
    }
    
    int x = pa.b + pa.c + pa.j;
    int y = pb.b + pb.c + pb.j;
    printf("%d %d %d\n", x,n-x-y,y);
    printf("%d %d %d\n",y,n-x-y,x);

    if (pa.b >= pa.c) {
        if (pa.b >= pa.j)printf("B");
        if (pa.b < pa.j)printf("J");
    }
    else {
        if (pa.c >= pa.j)printf("C");
        if (pa.c < pa.j)printf("J");
    }
    if (pb.b >= pb.c) {
        if (pb.b >= pb.j)printf(" B");
        if (pb.b < pb.j)printf(" J");
    }
    else {
        if (pb.c >= pb.j)printf(" C");
        if (pb.c < pb.j)printf(" J");
    }
    return 0;

}

Too long to improve

 

Posted by DavidP123 on Tue, 29 Oct 2019 10:36:50 -0700