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\n", &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\n%d %d %d\n", 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\n", mp[Jia_id], mp[Yi_id]);
    return 0;
}

1018 锤子剪刀布 (20 分)

上一篇:C++ Unicode SBCS 函数对照表


下一篇:开启全屏视频播放,全屏开启ie浏览器的C++代码实现