B1014. 福尔摩斯的约会

14/20

#include<bits/stdc++.h>
using namespace std;
map<char,string> day;
int main(){
    day['A']="MON";
    day['B']="TUE";
    day['C']="WED";
    day['D']="THU";
    day['E']="FRI";
    day['F']="SAT";
    day['G']="SUN";

    string a,b,c,d;
    char date;
    char hour;
    bool flag[2]={false};
    cin>>a>>b>>c>>d;
    int index=0,len=min(a.length(),b.length());
    for(int i=0;i<len;i++){
        if(flag[0]&&flag[1])break;//both found.
        //find 0~9 A~N
        if(flag[0]&&a[i]==b[i]&&((a[i]>=0&&a[i]<=9)||(a[i]>='A'&&a[i]<='N'))&&!flag[1]){hour=a[i];flag[1]=true;}
        //find A~G
        if(a[i]==b[i]&&a[i]>='A'&&a[i]<='G'&&!flag[0]){date=a[i];flag[0]=true;}
    }
    cout<<day[date]<<' ';
    if(hour>=0&&hour<=9)cout<<hour<<':';
    else cout<<10+hour-'A'<<':';


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

排查bug真是心酸。原来没有格式化,我下面的分钟都格式化了,却没有给小时格式化,太傻了。
20/20

#include<bits/stdc++.h>
using namespace std;
map<char,string> day;
int main(){
    day['A']="MON";
    day['B']="TUE";
    day['C']="WED";
    day['D']="THU";
    day['E']="FRI";
    day['F']="SAT";
    day['G']="SUN";

    string a,b,c,d;
    char date;
    char hour;
    bool flag[2]={false};
    cin>>a>>b>>c>>d;
    int len=min(a.length(),b.length());
    for(int i=0;i<len;i++){
        if(flag[0]&&flag[1])break;//both found.
        //find 0~9 A~N
        if(flag[0]&&a[i]==b[i]&&((a[i]>='0'&&a[i]<='9')||(a[i]>='A'&&a[i]<='N'))&&!flag[1]){hour=a[i];flag[1]=true;}
        //find A~G
        if(a[i]==b[i]&&a[i]>='A'&&a[i]<='G'&&!flag[0]){date=a[i];flag[0]=true;}
    }
    cout<<day[date]<<' ';
    if(hour>='0'&&hour<='9')printf("%02d:",hour-'0');
    else printf("%02d:",hour-'A'+10);


    int len2=min(c.length(),d.length());
    int index2=0;
    for(int i=0;i<len2;i++){
        if(c[i]==d[i]&&((c[i]>='a'&&c[i]<='z')||(c[i]<='Z'&&c[i]>='A'))){index2=i;break;}
    }
    printf("%02d\n",index2);
    return 0;
}
posted @ 2019-03-18 20:41  MarkKobs  阅读(265)  评论(0编辑  收藏  举报