其他分享
首页 > 其他分享> > PAT甲级 1061 Dating 模拟+字符串

PAT甲级 1061 Dating 模拟+字符串

作者:互联网

在这里插入图片描述

代码如下:

#include<iostream>
#include<string>
#include<math.h>
#include<stdio.h>
using namespace std;

string s1,s2,s3,s4;

int main(){
    cin>>s1>>s2>>s3>>s4;
    int min_len=min(s1.length(),s2.length());
    bool first=true;
    int pos=-1;
    for(int i=0;i<min_len;i++){
        if(s1[i]==s2[i]&&first&&s1[i]>='A'&&s1[i]<='G'){
            int date=s1[i]-'A'+1;
            pos=i;
            first=false;
            switch(date){
                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;
                default: break;
            }
            break;
        }
    }

    for(int i=pos+1;i<min_len;i++){
        if(s1[i]==s2[i]&&!first){
            if(s1[i]>='0'&&s1[i]<='9'){
                printf("%02d:",s1[i]-'0');
                break;
            }
            if(s1[i]>='A'&&s1[i]<='N'){
                printf("%d:",s1[i]-'A'+10);
                break;
            }
        }
    }

    min_len=min(s3.length(),s4.length());
    for(int i=0;i<min_len;i++){
        if(s3[i]==s4[i]&&((s3[i]>='a'&&s3[i]<='z')||(s3[i]>='A'&&s3[i]<='Z'))){
            printf("%02d",i);
            break;
        }
    }
    return 0;
}

标签:s3,PAT,1061,s2,s1,int,include,&&,Dating
来源: https://blog.csdn.net/weixin_44123362/article/details/100181416