天天看點

[PAT][Basic level]1018code review

NOT AC CODE:

2 problems to be resolved(4/6)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
using namespace std;
void print(int count_c,int count_j,int count_b )
{
 
    if( count_c > count_j){
        if(count_c >count_b){
            cout<<"C";
        }
        else if( count_c < count_b){
            cout<<"B";
        }
        else{
            cout<<"B";
        }
    }
    else if( count_c < count_j){
        if(count_c >count_b){
            cout<<"J";
        }
        else if( count_c < count_b){
            if(count_j < count_b){
                cout<<"B";
            }
            else if(count_j > count_b){
                cout<<"J";
            }else if( count_j == count_b){
                cout<<"B";
            }
        }
    }
    else if(count_c == count_j){
            if(count_c > count_b){
                cout<<"C";
            }
            else if(count_c < count_b){
                cout<<"B";
            }
            else if(count_c == count_b){
                cout<<"B";
            }
            
        }
    
    else if(count_j == count_c){
         cout<<"C";
    }
        
    
 return;   
}
int main()
{
    int n;
    cin>>n;
    char a,b;
    int a_win = 0,a_lose = 0,tie = 0;
    int count_a_C=0,count_a_J=0,count_a_B=0;
    int count_b_C=0,count_b_J=0,count_b_B=0;
    while(n--){
        cin>>a>>b;
        if(a == 'C'){
            //count_a_C ++;
            if(b =='C' ){
                //count_b_C++;
                tie ++;
            }
            else if(b == 'J'){
                //count_b_J++;
                a_win ++;
                count_a_C ++;
            }
            else if(b == 'B'){
                count_b_B++; 
                a_lose ++;
            }
        }
        
        if(a == 'J'){
           // count_a_J ++;
            if(b =='C' ){
                count_b_C++;
                a_lose ++;
            }
            else if(b == 'J'){
               // count_b_J++;
                tie ++;
            }
            else if(b == 'B'){
                //count_b_B++;
                a_win ++;
                count_a_J ++;
            }
        }
        
        if(a == 'B'){
            //count_a_B++;
            if(b =='C' ){
                //count_b_C++;
                a_win++;
                count_a_B ++;
            }
            else if(b == 'J'){
                count_b_J++;
                a_lose++;
            }
            else if(b == 'B'){
                //count_b_B ++;
                tie ++;
            }
        }
       
    }
    
    cout<<a_win<<" "<<tie<<" "<<a_lose<<endl;
    cout<<a_lose<<" "<<tie<<" "<<a_win<<endl;
    
    print(count_a_C,count_a_J,count_a_B);
    cout<<" ";
    
    print(count_b_C,count_b_J,count_b_B);
    
   
    
    
    
    return 0;
}