1018. 鎚子剪刀布

來源:互聯網
上載者:User

標籤:c++   pat   

現給出兩人的交鋒記錄,請統計雙方的勝、平、負次數,並且給出雙方分別出什麼手勢的勝算最大。

輸入格式:

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

輸出格式:

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

#include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;int change (char a){    switch (a)    {           case 'B':return 0;           case 'C':return 1;           case 'J':return 2;           }    }int main (){    int num;    scanf("%d",&num);    char hand[3]={'B','C','J'};    char first,second;    int k1,k2;    int times[3]={0},sort1[3]={0},sort2[3]={0};    for(int i=0;i<num;i++)    {            cin>>first;            cin>>second;            k1=change(first);            k2=change(second);            if( (k1+1)%3==k2)            {                times[0]++;                sort1[k1]++;                }            else if(k1==k2)            {                 times[1]++;                 }            else if( (k2+1)%3==k1)            {                times[2]++;                sort2[k2]++;                }            }    printf("%d %d %d\n",times[0],times[1],times[2]);    printf("%d %d %d\n",times[2],times[1],times[0]);        int j1=0,j2=0;    for(int i=0;i<3;i++)    {         if(sort1[i]>sort1[j1]) j1=i;         if(sort2[i]>sort2[j2]) j2=i;         }    printf("%c %c\n",hand[j1],hand[j2]);    system("pause");    return 0;    }

1018. 鎚子剪刀布

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.