PTA B1018 锤子剪刀布

 字母转换成数字 程序会简洁许多

按字典序输出,所以排了循环数组,可以判断胜负,转换成对应数字。+1%3相等 就赢了。

赢手势次数 也是数组相应位置内数字 比较

注意:

用getchar()吸收回车符

输入格式为 %c %c 会跳过空格符

#include<cstdio>
int change(char c){
  if(c=='B')return 0;
  else if(c=='C') return 1;
  else  return 2;
}
int main(){
  int n;
  char mp[3]={'B','C','J'};
  int time_A[3]={0};
  int time_B[3]={0};
  int hand_A[3]={0};
  int hand_B[3]={0};
  char a,b;
  int k1,k2;
    scanf("%d",&n);
    while(n--){
      getchar();
      scanf("%c %c",&a,&b);
      k1=change(a);
      k2=change(b);
      if((k1+1)%3==k2){
        time_A[0]+=1;
        time_B[2]+=1;
        hand_A[k1]+=1;
      }
      else if(k1==k2){
        time_A[1]+=1;
        time_B[1]+=1;
      }
      else{
        time_A[2]+=1;
        time_B[0]+=1;
        hand_B[k2]+=1;
      }
      
    }
    printf("%d %d %d\n",time_A[0],time_A[1],time_A[2]);
    printf("%d %d %d\n",time_B[0],time_B[1],time_B[2]);
    int h1=0,h2=0;
    for(int i=0;i<3;i++){
      if(hand_A[i]>hand_A[h1]){
        h1=i;
      }
      if(hand_B[i]>hand_B[h2]){
        h2=i;
      }
    }
    printf("%c %c\n",mp[h1],mp[h2]);
    
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值