1061 Dating (20 分)

1061 Dating (20 分)

Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

Input Specification:

Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.

Output Specification:

For each test case, print the decoded time in one line, in the format DAY HH:MM, where DAY is a 3-character abbreviation for the days in a week -- that is, MON for Monday, TUE for Tuesday, WED for Wednesday, THU for Thursday, FRI for Friday, SAT for Saturday, and SUN for Sunday. It is guaranteed that the result is unique for each case.

Sample Input:

3485djDkxh4hhGE 
2984akDfkkkkggEdsb 
s&hgsfdk 
d&Hyscvnm

Sample Output:

THU 14:04

注意:题目中common letter不仅要字母相同,位置也要相同(题目没有将这一点表达清晰,PAT出的题目表达总是不够严谨,也不懂为什么非要use in English又表达不清 也是呵呵~)

1、前两个字符串中第一个common letter表示星期X,要求字母大写且在A~G内

2、前两个字符串中第二项common letter表示小时,0~9和A~N表示

3、后两个字符串的第一个(或者唯一一个)common letter表示分钟,可是是小写字母也可以是大写字母,不能是其他字符

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


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


int main()
{
    string s1,s2,s3,s4,day;
    int h,m;
    cin >>s1>>s2>>s3>>s4;
    int flag = 1;
    for(int i = 0; i < min(s1.size(),s2.size()); i++){
        if(flag==1&&s1[i]==s2[i]&&s1[i]>='A'&&s1[i]<='G'){
                flag++;
                day = week[s1[i]-'A'];
        }
        else if(flag==2&&s1[i]==s2[i]&&((s1[i]>='A'&&s1[i]<='N')||(s1[i]>='0'&&s1[i]<='9'))){
                if(s1[i]>='A'&&s1[i]<='Z')
                    h = s1[i]-'A'+10;
                else h = s1[i]-'0';
                break;
        }
    }
    for(int i = 0; i < min(s3.size(),s4.size()); i++){
        if(s3[i]==s4[i]&&((s3[i]>='a'&&s3[i]<='z')||(s3[i]>='A'&&s3[i]<='Z'))){
            m = i;
            break;
        }
    }
    cout << day << " ";
    printf("%02d:%02d",h,m);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_36313227/article/details/89042149