PAT答案(锤子剪刀布)

题目链接

https://www.nowcoder.com/pat/6/problem/4044

代码
#include<iostream>
#include<string.h>
#include<algorithm>

using namespace std;
#define MAX 105
typedef struct Game{
    char one;
    char two;
} game;
int main() {
    int n;
    game games[MAX];
    int a[6], b[6];
    int pos[2];
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(pos, 0, sizeof(pos));
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        cin >> games[i].one >> games[i].two;
        if(games[i].one == games[i].two) {
            a[1]++;
            b[1]++;
        }else if( (games[i].one == 'B' && games[i].two == 'C')||(games[i].one == 'C' && games[i].two == 'J')||(games[i].one == 'J' && games[i].two == 'B') ) {
            if(games[i].one == 'B') a[3]++;
            else if(games[i].one == 'C') a[4]++;
            else a[5]++;
            a[0]++;
            b[2]++;
        }
        else{
            if(games[i].two == 'B') b[3]++;
            else if(games[i].two == 'C') b[4]++;
            else b[5]++;
            a[2]++;
            b[0]++;
        }
    }
    for(int i=0; i<2; i++) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[2]);
    for(int i=0; i<2; i++) {
        printf("%d ", b[i]);
    }
    printf("%d\n", b[2]);
    pos[0] = max_element(a+3, a+6) - a - 3;
    pos[1] = max_element(b+3, b+6) - b -3;
    for(int i=0; i<2; i++) {
        if(pos[i] == 0) printf("B");
        else if(pos[i] == 1) printf("C");
        else printf("J");
        if(i == 0) printf(" ");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值