0基础PAT乙级刷题之路(七)-1018 锤子剪刀布 (20分)

1018 锤子剪刀布 (20分)

这道题结尾好暴力啊!

大家应该都会玩“锤子剪刀布”的游戏:现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。

输入格式:
输入第 1 行给出正整数 N(≤10
​5
​​ ),即双方交锋的次数。随后 N 行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C 代表“锤子”、J 代表“剪刀”、B 代表“布”,第 1 个字母代表甲方,第 2 个代表乙方,中间有 1 个空格。

输出格式:
输出第 1、2 行分别给出甲、乙的胜、平、负次数,数字间以 1 个空格分隔。第 3 行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有 1 个空格。如果解不唯一,则输出按字母序最小的解。

输入样例:
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J

输出样例:
5 3 2
2 3 5
B B

#include
#include
#include
#include
using namespace std;

int main(){
    int n;
    int jia_c=0,jia_j=0,jia_b=0;
    int yi_c=0,yi_j=0,yi_b=0;
    int count_jia=0,count_yi=0,count_ping=0;
    cin>>n;
    vector<char> jia(n);
    vector<char> yi(n);
    for(int i=0;i<n;i++){
        cin>>jia[i]>>yi[i];
        if(jia[i]==yi[i]) count_ping+=1;
        else{
            if(jia[i]=='C'&&yi[i]=='J'){
                jia_c+=1;
                count_jia+=1;
            }
            if(jia[i]=='C'&&yi[i]=='B'){
                yi_b+=1;
                count_yi+=1;
            }
            if(jia[i]=='J'&&yi[i]=='C'){
                yi_c+=1;
                count_yi+=1;
            }
            if(jia[i]=='J'&&yi[i]=='B'){
                jia_j+=1;
                count_jia+=1;
            }
            if(jia[i]=='B'&&yi[i]=='J'){
                yi_j+=1;
                count_yi+=1;
            }
            if(jia[i]=='B'&&yi[i]=='C'){
                jia_b+=1;
                count_jia+=1;
            }
        }
    }
    cout<<count_jia<<" "<<count_ping<<" "<<(n-count_jia-count_ping)<<endl;
    cout<<count_yi<<" "<<count_ping<<" "<<(n-count_yi-count_ping)<<endl;
    
    if(jia_b==jia_c&&jia_c==jia_j&&jia_b==jia_j) cout<<"B"<<" ";
    
    //输出甲
    if(jia_b==jia_c&&jia_c>jia_j) cout<<"B"<<" ";
    if(jia_b==jia_j&&jia_c<jia_j) cout<<"B"<<" ";
    if(jia_j==jia_c&&jia_b<jia_j) cout<<"C"<<" ";
    
    if(jia_b>jia_c&&jia_b>jia_j) cout<<"B"<<" ";
    if(jia_c>jia_b&&jia_c>jia_j) cout<<"C"<<" ";
    if(jia_j>jia_b&&jia_j>jia_c) cout<<"J"<<" ";
    
    //输出乙
    if(yi_b==yi_c&&yi_c==yi_j&&yi_b==yi_j) cout<<"B";
    
    if(yi_b==yi_c&&yi_c>yi_j) cout<<"B"<<" ";
    if(yi_b==yi_j&&yi_c<yi_j) cout<<"B"<<" ";
    if(yi_j==yi_c&&yi_b<yi_j) cout<<"C"<<" ";
    
    if(yi_b>yi_c&&yi_b>yi_j) cout<<"B";
    if(yi_c>yi_b&&yi_c>yi_j) cout<<"C";
    if(yi_j>yi_b&&yi_j>yi_c) cout<<"J";
    
}

你可能感兴趣的:(PAT乙级)