pat-B1018- hammer scissors

Topic Link -> Link

Thinking

  1. c [3] A recording wins, flat, negative number, corresponding to a methyl acetate game outcome inverted.
  2. win1 [3] A recording respectively with a hammer, scissors, cloth winning number, the same token, win2 [3] acetate recording.
  3. Respectively identify maximum win1 [3], win2 [3], the attention required by the lexicographical order.

Code

ps: the code a bit ugly ...

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>

using namespace std;

int main(){
    int win1[3]={0},win2[3]={0},c[3]={0},n;//win[3]存储锤子剪刀布赢的次数,c[3]存储甲胜、平、负次数
    scanf("%d",&n);
    while(n--){
        char a,b;//代表甲、乙
        cin>>a>>b;
        if(a=='C'&&b=='J'){//甲锤子乙剪刀
            win1[1]++;
            c[0]++;
        }
        else if(a=='J'&&b=='B'){//甲剪刀乙布
            win1[2]++;
            c[0]++;
        }
        else if(a=='B'&&b=='C'){//甲布乙锤子
            win1[0]++;
            c[0]++;
        }
        else if(a==b){//甲乙平局
            c[1]++;
        }
        else if(a=='C'&&b=='B'){//甲锤子乙布
            win2[0]++;
            c[2]++;
        }
        else if(a=='J'&&b=='C'){//甲剪刀乙锤子
            win2[1]++;
            c[2]++;
        }
        else if(a=='B'&&b=='J'){//甲布乙剪刀
            win2[2]++;
            c[2]++;
        }
    }//while
    int maxa=win1[0],maxb=win2[0],flag1=0,flag2=0;
    for(int i=0;i<3;i++){
        if(win1[i]>maxa){
            maxa=win1[i];
            flag1=i;
        }
        if(win2[i]>maxb){
            maxb=win2[i];
            flag2=i;
        }
    }
    printf("%d %d %d\n",c[0],c[1],c[2]);
    printf("%d %d %d\n",c[2],c[1],c[0]);
    if(flag1==0)printf("B ");
    else if(flag1==1)printf("C ");
    else if(flag1==2)printf("J ");
    if(flag2==1)printf("C\n");
    else if(flag2==2)printf("J\n");
    else if(flag2==0)printf("B\n");
    return 0;
}

Released eight original articles · won praise 1 · views 128

Guess you like

Origin blog.csdn.net/MichealWu98/article/details/104009324