1018. Hammer Scissors Cloth

Everyone should play the game of "hammer, paper, scissors": two people give gestures at the same time, 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 which gestures respectively. .
Input format:
Enter the first line to give a positive integer N (<=105), that is, the number of times the two sides fought. Then there are N lines, each line gives the information of a confrontation, that is, the gestures given by both A and B 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 the middle.
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 with the most wins by A and B, with a space in between. If the solutions are not unique, the alphabetically smallest solution is output.
Input sample:
10
CJ
JB
CB
BB
BC
CC
CB
JB
BC
JJ
Output sample:
5 3 2
2 3 5
BB
Note: The transformation of the size determination into a computer problem is actually the comparison of the size of the numerical value, so it is easy to think of using ASCII The size of the code determines the winner. It can also be called by writing a function, but it is more troublesome. Finally, pay attention to some small details of the output. To make the output small in order, you should pay attention to the placement of the equal sign.

#include<stdio.h>
int main()
{
    int i, n, m, Jic=0, Jij=0, Jib=0, P=0, Yic=0, Yij=0, Yib=0;
    char a, b;
    scanf("%d", &n);//输入执行次数
    getchar();//输入回车换行,有连续字符输入一定要注意需不需要设置空格读取
    for (i=1; i<=n; i++){
        scanf("%c %c", &a, &b);//读取一个空格,不能使用%c,否则b会读取成空格
        getchar();//输入回车换行
        m = a-b;
        switch (m){//这里容易混,一定要仔细
            case -7: Jic++; break;//C>J
            case  8: Jij++; break;//J>B
            case -1: Jib++; break;//B>C
            case  0:   P++; break;//平局
            case  1: Yib++; break;//C<B
            case  7: Yic++; break;//J<C
            case -8: Yij++; break;//B<J
        }
    }
    printf("%d %d %d\n", Jic+Jij+Jib, P, Yic+Yij+Yib);//输出正、平、负
    printf("%d %d %d\n", Yic+Yij+Yib, P, Jic+Jij+Jib);

    if (Jic<Jij && Jib<Jij) printf("J ");//先输出甲数据所以要保留一个空格
    else if (Jic>Jib) printf("C ");//else if语句所有条件并集是全集
    else printf("B ");
    if (Yic<Yij && Yib<Yij) printf("J");
    else if (Yic>Yib) printf("C");//当两者出现相等时,要输出序小的,等号就必须放在后面的条件里
    else printf("B");
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325584440&siteId=291194637