zoukankan      html  css  js  c++  java
  • PAT B1018.锤子剪刀布(20)

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

    #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("
    ");
    			*/
            }
            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 %d
    ", count[0], count[2], count[1]);
        printf("%d %d %d
    ", 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 %d
    ",Jy,Jp,Js);
        printf("%d %d %d
    ",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("
    ");
        return 0;
    }
     
    --------------------- 
    作者:fengwuyaQAQ 
    来源:CSDN 
    原文:https://blog.csdn.net/fengwuyaQAQ/article/details/85616584 
    版权声明:本文为博主原创文章,转载请附上博文链接!
    
  • 相关阅读:
    16、springboot——错误处理原理+定制错误页面(1)
    15、springboot——CRUD-跳转到修改员工页面+员工修改和删除实现 ⑥
    14、springboot——CRUD-跳转到添加员工页面+员工添加实现⑤
    13、springboot——CRUD-thymeleaf公共页面元素抽取④
    12、springboot——CRUD登录和拦截③
    11、springboot——CRUD国际化②
    10、springboot——CRUD导入静态资源以及设置默认访问首页①
    9、springmvc的自动配置
    8、模板引擎thymeleaf(百里香叶)
    7、对静态资源映射的规则
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11191705.html
Copyright © 2011-2022 走看看