PAT 三月 18, 2020

PAT甲级 1061 Dating (20分)

文章字数 4.1k 阅读约需 4 mins. 阅读次数 -

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

注意点

  • 三对相同的字符都需要在对应相同的位置上(在各自的字符串中所在的位置相同),这一点题目没有说清楚(我刚开始以为可以在不同位置
  • 第 2 对相同的字符,其实是在第一对字符位置之后的下一对满足条件的字符,而不是从头扫描碰到的第 2 对,这一点题目也没有说清楚
  • 前两对字符需要限定到具体范围,如 A~G 与 A~N,而不是 A~Z,否则会“答案错误”
  • 总之,这题很模糊,能做对靠猜
#include <cstdio>
#include <cstring>

const int maxn = 61;

int main() {
    char str[4][maxn];
    char week[7][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    for (int i = 0; i < 4; i++) {
        scanf("%s", str[i]);
    }
    int i, j, len1 = strlen(str[0]), len2 = strlen(str[1]), len3 = strlen(str[2]), len4 = strlen(str[3]);
    for (i = 0; i < len1 && i < len2; i++) {
        if (str[0][i] == str[1][i] && str[0][i] >= 'A' && str[0][i] <= 'G') {
            printf("%s ", week[str[0][i] - 'A']);
            break;
        }
    }
    for (i++; i < len1 && i < len2; i++) {
        if (str[0][i] == str[1][i]) {
            if (str[0][i] >= '0' && str[0][i] <= '9') {
                printf("%02d:", str[0][i] - '0');
                break;
            } else if (str[0][i] >= 'A' && str[0][i] <= 'N') {
                printf("%02d:", str[0][i] - 'A' + 10);
                break;
            }
        }
    }
    for (int i = 0; i < len3 && i < len4; i++) {
        if (str[2][i] == str[3][i] && (str[2][i] >= 'a' && str[2][i] <= 'z' || str[2][i] >= 'A' && str[2][i] <= 'Z')) {
            printf("%02d", i);
            break;
        }
    }
    return 0;
}
0%