0基础PAT乙级刷题之路(四)—1014 福尔摩斯的约会 (20分)

这道题好细节啊,思路简单,注意一下题干中的几个条件就好了

0基础PAT乙级刷题之路(四)—1014 福尔摩斯的约会 (20分)_第1张图片

#include 

using namespace std;

int main(void){
    string day_hour1;
    string day_hour2;
    char day,hour;
    int min;
    int mark = 0;//判定day_hour中,是否是第一次出现
    string min1;
    string min2;
    
    cin>>day_hour1>>day_hour2>>min1>>min2;
    
    //下面开始获取day hour min
    for(int i=0;i<day_hour1.length()&&i<day_hour2.length();i++){
        if(day_hour1[i]==day_hour2[i]&&mark==0&&day_hour1[i]>='A'&&day_hour1[i]<='G'){
            day = day_hour1[i];
            mark = 1;//下次再遇到相同字符,则不会赋值给day
            continue;
        }
        if(day_hour1[i]==day_hour2[i]&&mark==1){
            if((day_hour1[i]>='A'&&day_hour1[i]<='N')||(day_hour1[i]>='0'&&day_hour1[i]<='9')){
                hour = day_hour1[i];
                break;
            }
            
        }
    }
    
    for(int i=0;i<min1.length()&&i<min2.length();i++){
        if(min1[i]==min2[i]&&min1[i]>='A'&&min1[i]<='z')		{
            min = i;
            break;
        }
    }
    //现在我们已经得到了day hour min,下面就是输出

	int day_num=day-'A'+1;
    switch(day_num){
        case 1:{cout<<"MON"<<" ";break;}
        case 2:{cout<<"TUE"<<" ";break;}
        case 3:{cout<<"WED"<<" ";break;}
        case 4:{cout<<"THU"<<" ";break;}
        case 5:{cout<<"FRI"<<" ";break;}
        case 6:{cout<<"SAT"<<" ";break;}
        case 7:{cout<<"SUN"<<" ";break;}
    }//day输出完成
    
    if(hour<='9'&&hour>='0')
        cout<<"0"<<(hour-'0')<<":";
    else
        cout<<(hour-'A'+10)<<":";
    //hour输出完成
    
    if(min<10)
        cout<<"0"<<min<<endl;
    else
        cout<<min<<endl;//ok,完工
}

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