PAT B1014/A1016

大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母’D’,代表星期四;第2对相同的字符是’E’,那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母’s’出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。

输入格式:

输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。

输出格式:

在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。

输入样例:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
输出样例:
THU 14:04

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

#include "stdio.h"
//#include "math.h"
#include "string.h"
//#include "algorithm"
//using namespace std;
char week[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main(){
    char str1[70], str2[70], str3[70], str4[70];
    gets(str1);
    gets(str2);
    gets(str3);
    gets(str4);
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int len3 = strlen(str3);
    int len4 = strlen(str4);
    int i = 0;
    //寻找str1 str2中第一对相同位置的A ~ G的大写字母
    for (i = 0; i < len1 && i < len2; i++) {
        if (str1[i] == str2[i] && str1[i] >= 'A' && str1[i] <= 'G') {
            printf("%s ",week[str1[i] - 'A']);
            break;
        }
    }
    //在上面的基础上,往后寻找相同位置的0 ~ 9、A ~ N的字符
    for (i++; i < len1 && i < len2; i++) {
        if (str1[i] == str2[i] ) {
            if (str1[i] >= '0' && str1[i] <= '9') {
                printf("%02d:", str1[i] - '0');
                break;
            }else if(str1[i] >= 'A' && str1[i] <= 'N'){
                printf("%02d:", str1[i] - 'A' + 10);
                break;
            }
        }
    }
    //寻找str3 和str4 中第一对相同位置的A~Z或a~z的英文字母
    for (i = 0; i < len3 && i < len4; i++) {
        if (str3[i] == str4[i]) {
            if ((str3[i] >= 'A' && str3[i] <= 'Z') || (str3[i] >= 'a' && str3[i] <= 'z')) {
                printf("%02d", i);
                break;
            }
        }
    }
    return 0;
}