锤子剪刀布

输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代
表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯
一,则输出按字母序最小的解。

public class Main{

    public static void main(String[] args){

        int count = 1;

        int num = 0;

        List<String> strs = new ArrayList<String>();

        Scanner sc = new Scanner(System.in);

        while(sc.hasNextLine()){

            if(count == 1){

                num = Integer.parseInt(sc.nextLine());

                count ++;

            }else if(num+1>count){

                strs.add(sc.nextLine());

                count++;

            }else if(num+1==count){

                strs.add(sc.nextLine());

                break;

            }else{

                break;

            }

        }

        result(strs);

    }

    public static void result(List<String> strs){

        int v = 0;

        int p = 0;

        int f = 0;

        String jia = "";

        String yi = "";

        for(String s:strs){

            String[] strss = s.split(" ");

            

             

            if(change(s) == 1){

                 jia+=strss[0];

                v++;

            }else if(change(s) == 2) {

                yi+=strss[1];

                f++;

            }else{

                p++;

            }

        }

        System.out.println(v+" "+p+" "+f);

        System.out.println(f+" "+p+" "+v);

        System.out.print(count(jia)+" "+count(yi));

    }

    public static int change(String s){

        String[] strs = s.split(" ");

        if(strs[0].equals("J")&&strs[1].equals("B")){

            return 1;

        }else if(strs[0].equals("C")&&strs[1].equals("J")){

            return 1;

        }else if(strs[0].equals("B")&&strs[1].equals("C")){

            return 1;

        }else if(strs[0].equals(strs[1])){

            return 3;

        }else{

            return 2;

        }

    }

     public static char count(String s){

       char[] ca = s.toCharArray();

       int B = 0;

       int C = 0;

       int J = 0;

       for(char c : ca){

           if(c == 'B'){

               B++;

           }

           if(c=='C'){

               C++;

           }

           if(c=='J'){

               J++;

           }

       }

        if(B>=C&&B>=J){

            return 'B';

        }else if(C>B&&C>=J){

            return 'C';

        }else{

            return 'J';

        }

          

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值