一个没有通过,不知道为何

#include <cstdio>
int change(char c) {
    if(c == 'B') return 0;
    if(c == 'C') return 1;
    if(c == 'J') return 2;
}
int judge(int a, int b) {
    if(a == b) return 3;
    else if(a == 'B' && b == 'C') return 1;
    else if(a == 'B' && b == 'J') return 2;
    else if(a == 'C' && b == 'B') return 2;
    else if(a == 'C' && b == 'J') return 1;
    else if(a == 'J' && b == 'B') return 1;
    else if(a == 'J' && b == 'C') return 2;
}

int main() {
    char str[] = {'B', 'C', 'J'};
    int n = 0;
    scanf("%d", &n);
    //count[0]:甲赢 count[1]:甲负 count[2]:甲平
    //count[3]:乙赢 count[4]:乙负 count[5]:乙平
    int count[6] = {0};
    //times[0]~times[5]:甲乙分别用锤子,剪刀,布赢的次数
    int times[6] = {0};
    int id1 = 0, id2 = 0; //甲乙分别赢的最多的手势
    for(int i = 0; i < n; i++) {
        char a, b;
        getchar();
        scanf("%c %c", &a, &b);
        int temp = judge(a, b);
        if(temp == 1) {
            count[0]++;
            count[4]++;
            times[change(a)]++;//甲赢使用的手势加一
            /*for(int i = 0; i < 6; i++) {
                printf("--%d", times[i]);
            }
            printf("n");
            */
        }
        if(temp == 2) {
            count[1]++;
            count[3]++;
            times[change(b)+3]++;//甲乙赢使用的手势加一
        }
        if(temp == 3) {
            count[2]++;
            count[5]++;
        }
    }
    for(int i = 0; i < 3; i++) {
        if(times[i] > times[id1]) id1 = i;
        if(times[i+3] > times[id2]) id2 = i;
    }
    printf("%d %d %dn", count[0], count[2], count[1]);
    printf("%d %d %dn", count[3], count[5], count[4]);
    printf("%c %c", str[id1], str[id2]);
    return 0;
}

全部AC

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<ctime>
using namespace std;

int main()
{
    int N;
    scanf("%d",&N);
    int Jy=0,Jp=0,Js=0;
    int J[3]={0},Y[3]={0}; //B 0 C 1 J 2
    char s1,s2;
    for(int i=1;i<=N;i++){
        getchar();
        scanf("%c %c",&s1,&s2);
        if(s1==s2) Jp++;
        else if(s1=='C'&&s2=='J'){
            Jy++;
            J[1]++;
        }else if(s1=='J'&&s2=='B'){
            Jy++;
            J[2]++;
        }else if(s1=='B'&&s2=='C'){
            Jy++;
            J[0]++;
        }else{
            if(s2=='C') Y[1]++;
            else if(s2=='J') Y[2]++;
            else Y[0]++;
            Js++;
        }
    }
    printf("%d %d %dn",Jy,Jp,Js);
    printf("%d %d %dn",Js,Jp,Jy);
    if(J[0]>=J[1] && J[0]>=J[2]) printf("B ");
    else if(J[1]>=J[2]) printf("C ");
    else printf("J ");
    if(Y[0]>=Y[1] && Y[0]>=Y[2]) printf("B");
    else if(Y[1]>=Y[2]) printf("C");
    else printf("J");
    printf("n");
    return 0;
}
 
--------------------- 
作者:fengwuyaQAQ 
来源:CSDN 
原文:https://blog.csdn.net/fengwuyaQAQ/article/details/85616584 
版权声明:本文为博主原创文章,转载请附上博文链接!
内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!