码迷,mamicode.com
首页 > 移动开发 > 详细

1018 锤子剪刀布 (20 分)

时间:2019-01-30 23:05:02      阅读:380      评论:0      收藏:0      [点我收藏+]

标签:clu   flow   hand   stdio.h   _id   get   win   fail   game   

#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 分)

标签:clu   flow   hand   stdio.h   _id   get   win   fail   game   

原文地址:https://www.cnblogs.com/Yaxadu/p/10340041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!