1018 锤子剪刀布 (20 分)

Posted yaxadu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1018 锤子剪刀布 (20 分)相关的知识,希望对你有一定的参考价值。

#include<stdio.h>
int game(char A, char B) {
    if (A == B) return 0;
    if (A == ‘C‘) {
        if (B == ‘J‘) return 1;
        else return -1;
    }
    if (A == ‘J‘) {
        if (B == ‘B‘) return 1;
        else return -1;
    }
    if (A == ‘B‘) {
        if (B == ‘C‘) return 1;
        else return -1;
    }
}
int change(char a) {
    if (a == ‘B‘) return 0; 
    if (a == ‘C‘) return 1;
    if (a == ‘J‘) return 2;
}
int main() {
    int n, Jia_win = 0, JIa_flow = 0, Jia_fail = 0;
    int Yi_win = 0, Yi_flow = 0, Yi_fail = 0;
    int hand_Jia[3] = { 0 }, hand_Yi[3] = { 0 };
    scanf("%d", &n);
    getchar();
    while (n--) {
        char Jia, Yi;
        scanf("%c %c
", &Jia, &Yi);
        if (game(Jia, Yi) == 1) {
            Jia_win++;
            Yi_fail++;
            hand_Jia[change(Jia)]++;
        }
        else if (game(Jia, Yi) == 0) {
            JIa_flow++;
            Yi_flow++;
        }
        else {
            Jia_fail++;
            Yi_win++;
            hand_Yi[change(Yi)]++;
        }
    }
    printf("%d %d %d
%d %d %d
", Jia_win, JIa_flow, Jia_fail, Yi_win, Yi_flow, Yi_fail);
    int Jia_id = 0, Yi_id = 0;
    for (int i = 0; i < 3; i++) {
        if (hand_Jia[i] > hand_Jia[Jia_id]) Jia_id = i;
        if (hand_Yi[i] > hand_Yi[Yi_id]) Yi_id = i;
    }
    char mp[3] = { ‘B‘, ‘C‘, ‘J‘ };
    printf("%c %c
", mp[Jia_id], mp[Yi_id]);
    return 0;
}

以上是关于1018 锤子剪刀布 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章

1018 锤子剪刀布 (20 分)

1018 锤子剪刀布 (20分)

PAT乙级 1018. 锤子剪刀布 (20)

1018. 锤子剪刀布 (20)

1018 锤子剪刀布 (20 分)

PAT乙级 1018 锤子剪刀布 (20 分)