1061. Dating (20)

简介: Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm".

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 <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    string s1, s2, s3, s4;
    string week[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    char w = 0;
    int h = 0, m = 0, j = 0;
    
    cin >> s1 >> s2 >> s3 >> s4;
    int len1 = (int)min(s1.length(), s2.length());
    int len2 = (int)min(s3.length(), s4.length());
    
    for (int i = 0; i < len1; i++) {
        if (s1[i] == s2[i] && s1[i] >= 'A' && s1[i] <= 'G') {
            w = s1[i];
            j = i + 1;
            break;
        }
    }
    for (; j < len1; j++) {
        if (s1[j] == s2[j] && ((s1[j] >= 'A' && s1[j] <= 'N') || isdigit(s1[j])) ) {
            if (isdigit(s1[j])) {
                h = s1[j] - '0';
            }else{
                h = s1[j] - 'A' + 10;
            }
            break;
        }
    }
    for (int i = 0; i < len2; i++) {
        if (s3[i] == s4[i] && isalpha(s3[i])) {
            m = i;
        }
    }
    cout << week[w-'A'];
    printf(" %02d:%02d\n", h, m);
    
    return 0;
}

目录
相关文章
|
定位技术
German collegiate programming contest 2012 - Ski Jumping
首先用动能定理算出平抛的初速度v0,然后分三种情况,0~L/2,L/2~L,L~无穷远。
138 0
German collegiate programming contest 2012 - Ski Jumping
HDU-1027,Ignatius and the Princess II
HDU-1027,Ignatius and the Princess II
|
人工智能 BI 容器