PAT1018 錘子剪刀布(滿分20 得10分)

2020-08-12 23:52:13

菜的不行。。。。記錄一下用最笨的方法做的,有空回來看看哪裏有問題。

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
    int N,awin=0,bwin=0,abwin=0,ab=0,aj=0,ac=0,bb=0,bj=0,bc=0;
    char amax;
    char bmax;
    int asmax=0;
    int bsmax=0;
    cin>>N;

    for(int i=0;i<N;i++)
    {
        char A,B;
        cin>>A>>B;
        if(A=='C'&&B=='J')
        {
            ac++;
            bj++;
            awin++;

        }
        else if(A=='J'&&B=='B')
        {
            aj++;
            bb++;
            awin++;
        }
        else if(A=='B'&&B=='C')
        {
           ab++;
           bc++;
           awin++;
        }
        else if(B=='C'&&A=='J')
        {
            bc++;
            aj++;
            bwin++;
        }
        else if(B=='J'&&A=='B')
        {
            bj++;
            ab++;
            bwin++;
        }
        else if( B=='B'&&A=='C')
        {
            bb++;
            ac++;
            bwin++;
        }
        if(A==B)
        {
            if(A=='B')
            {
                ab++;
                bb++;
                abwin++;
            }
            if(A=='J')
            {
                aj++;
                bj++;
                abwin++;
            }
            if(A=='C')
            {
                ac++;
                bc++;
                abwin++;
            }
         }

    }
    cout<<awin<<" "<<abwin<<" "<<N-awin-abwin<<endl;
    cout<<bwin<<" "<<abwin<<" "<<N-bwin-abwin<<endl;
    asmax = ab;
    amax ='B';
    if(asmax<ac)
    {
        asmax =ac;
        amax = 'C';
    }

    if(asmax <aj)
    {
        asmax = aj;
        amax = 'J';
    }
    bsmax=bb;
    bmax ='B';
    if(bsmax<bc)
    {
        bsmax =bc;
        bmax = 'C';
    }

    if(bsmax <bj)
    {
        bsmax = bj;
        bmax = 'J';
    }
    cout<<amax<<" "<<bmax<<endl;
    return 0;
}