PAT甲级1061题(福尔摩斯)


1.题目介绍

1061

2.考察点,难度

字符串处理类,char字符判断,字母与数字判断,范围限度,难度易

3.解题代码

#include <bits/stdc++.h>
using namespace std;

string Week[7]={"MON ","TUE ","WED ","THU ","FRI ","SAT ","SUN "};

int main(){

    freopen("D:\\PAT\\Clion\\in.txt","r",stdin);
    string a,b,c,d,com1="0",com2="0";
    int com3;
    cin>>a>>b>>c>>d;
    if(a.length()>b.length()) swap(a,b);
    if(c.length()>d.length()) swap(c,d);
    for(int i=0;i<a.length();i++){
        if(a[i]==b[i] && com2=="0" && com1!="0" && ((a[i] >= 'A' && a[i] <= 'N')||isdigit(char(a[i]))))
            com2=tolower(a[i]);
        if(a[i]==b[i] && com1=="0" && (a[i] >= 'A' && a[i] <= 'G'))
            com1=tolower(a[i]);
    }
    for(int i=0;i<c.length();i++){
        if(c[i]==d[i] && isalpha(c[i])){
            com3=i;
            break;
        }
    }
    cout<<Week[com1[0]-'a'];
    if(isdigit(com2[0]))
        cout<<"0"<<com2<<":";
    else
        cout<<10+com2[0]-'a'<<":";

    if(com3<10)
        cout<<"0"<<com3<<endl;
    else
        cout<<com3<<endl;

    return 0;

}

4.原题地址

https://pintia.cn/problem-sets/994805342720868352/problems/994805411985604608


文章作者: Peyton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Peyton !
  目录