PTA B1018 锤子剪刀布

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fuckingone/article/details/82459744

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

按字典序输出,所以排了循环数组,可以判断胜负,转换成对应数字。+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]);
    
}

猜你喜欢

转载自blog.csdn.net/fuckingone/article/details/82459744