PAT甲级 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

注意点

  • 三对相同的字符都需要在对应相同的位置上(在各自的字符串中所在的位置相同),这一点题目没有说清楚(我刚开始以为可以在不同位置
  • 第 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;
}

文章作者: 吴鑫康
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 吴鑫康 !
评论
 上一篇
PAT甲级 1082 Read Number in Chinese (25分) PAT甲级 1082 Read Number in Chinese (25分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first
下一篇 
PAT乙级 1010 一元多项式求导 (25分) PAT乙级 1010 一元多项式求导 (25分)
设计函数求一元多项式的导数。(注:x^n(n为整数)的一阶导数为nx^{n−1}。) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。 输出格式:以与输入相同的格式输出导数多项式非
2020-03-17
  目录