天天看點

pat basic level 1018

題目網址:http://pat.zju.edu.cn/contests/pat-b-practise/1018

Github: https://github.com/kunth/evernote/blob/master/pat_basic_level_1018

//Date : 
//Author : fibonacci
//Note: http://pat.zju.edu.cn/contests/pat-b-practise/1018
//Accepted

//邏輯控制上要小心點,也不算複雜,這代碼比較難看懂。。。
//s 勝利, p 平局, f 負
//數組shou分别記錄兩個玩家勝利的手勢個數,按'B','C', 'J'順序

#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    char c1, c2;
    int N, s1,p1,f1,s2,p2,f2, shou1[3], shou2[3];//按'B','C', 'J'順序
    s1 = p1 = f1 = s2 = p2 = f2 = 0;
    memset(shou1, 0, sizeof(shou1));
    memset(shou2, 0, sizeof(shou2));
    //freopen("in.txt", "r", stdin);
    scanf("%d", &N);
    for(int i = 0; i < N; ++i)
    {
        getchar();
        scanf("%c %c", &c1, &c2);
        switch(c1)
        {
        case 'C':
            c1 > c2 ? (++f1, ++s2, ++shou2[0]) :( c1 == c2 ? (++p1, ++p2) : (++s1, ++f2, ++shou1[1]));
            break;
        case 'B':
            if(c2=='B')
                (++p1, ++p2);
            else if(c2=='C')
                (++s1, ++f2, ++shou1[0]);
            else
                (++f1, ++s2, ++shou2[2]);
            break;
        case 'J':
            if(c2=='B')
                (++s1, ++f2, ++shou1[2]);
            else if(c2=='J')
                (++p1, ++p2);
            else
                (++f1, ++s2, ++shou2[1]);
        }
    }
    printf("%d %d %d\n", s1, p1, f1);
    printf("%d %d %d\n", s2, p2, f2);
    (shou1[0] >= shou1[1] && shou1[0] >= shou1[2]) ? printf("B ") :(shou1[1]>=shou1[2] ? printf("C ") : printf("J "));
    (shou2[0] >= shou2[1] && shou2[0] >= shou2[2]) ? printf("B\n") :(shou2[1]>=shou2[2] ? printf("C\n") : printf("J\n"));
    return 0;
}