鎚子剪刀布

來源:互聯網
上載者:User

標籤:鎚子剪刀布


題目描述
大家應該都會玩“鎚子剪刀布”的遊戲:現給出兩人的交鋒記錄,請統計雙方的勝、平、負次數,並且給出雙方分別出什麼手勢的勝算最大。


輸入描述:
輸入第1行給出正整數N(<=105),即雙方交鋒的次數。隨後N行,每行給出一次交鋒的資訊,即甲、乙雙方同時給出的的手勢。C代表“鎚子”、J代表“剪刀”、B代表“布”,第1個字母代表甲方,第2個代表乙方,中間有1個空格。



輸出描述:
輸出第1、2行分別給出甲、乙的勝、平、負次數,數字間以1個空格分隔。第3行給出兩個字母,分別代表甲、乙獲勝次數最多的手勢,中間有1個空格。如果解不唯一,則輸出按字母序最小的解。


輸入例子:
10C JJ BC BB BB CC CC BJ BB CJ J


輸出例子:
5 3 22 3 5B B
參考代碼:
#include<stdio.h>#include<stdlib.h>#define MAX(A,B,C) (A>=B&&A>=C)?'B':(B>=C)?'C':'J'int comp(char A,char B){    if(A==B)      return 0;    else if(A=='B'&&B=='C')      return 1;    else if(A=='C'&&B=='J')      return 1;    else if(A=='J'&&B=='B')      return 1;    else       return -1;}int main(){    int num,A_count_B=0,A_count_C=0,A_count_J=0,B_count_B=0,B_count_C=0,B_count_J=0,Win_count=0,Lose_count=0;    scanf("%d",&num);    char game[num][2];    int i,flag;    for(i=0;i<num;i++){      getchar();      scanf("%c %c",&game[i][0],&game[i][1]);    }    for(i=0;i<num;i++){        flag=comp(game[i][0],game[i][1]);        if(flag>0){            Win_count++;            if(game[i][0]=='B')              A_count_B++;            else if(game[i][0]=='C')              A_count_C++;            else              A_count_J++;        }else if(flag<0){            Lose_count++;            if(game[i][1]=='B')              B_count_B++;            else if(game[i][1]=='C')              B_count_C++;            else              B_count_J++;        }    }    printf("%d %d %d\n",Win_count,num-Win_count-Lose_count,Lose_count);    printf("%d %d %d\n",Lose_count,num-Win_count-Lose_count,Win_count);    printf("%c %c\n",MAX(A_count_B,A_count_C,A_count_J),MAX(B_count_B,B_count_C,B_count_J));    return 0;}

原題連結:https://www.nowcoder.com/pat/6/problem/4044

鎚子剪刀布

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.