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;
}

目录
相关文章
|
机器学习/深度学习 人工智能
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
49 0
A Knight&#39;s Journey
总时间限制: 1000ms 内存限制: 65536kB描述BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the world.
1167 0
|
机器学习/深度学习
[Everyday Mathematics]20150301
设 $f(x)$ 在 $[-1,1]$ 上有任意阶导数, $f^{(n)}(0)=0$, 其中 $n$ 是任意正整数, 且存在 $C>0$, $$\bex |f^{(n)}(x)|\leq C^nn!,\quad \forall\ n\in\bbN,\quad \forall\ x\in[-1,1].
655 0
[Everyday Mathematics]20150220
试求 $$\bex \sum_{k=0}^\infty\frac{1}{(4k+1)(4k+2)(4k+3)(4k+4)}. \eex$$
506 0
[Everyday Mathematics]20150224
设 $A,B$ 是 $n$ 阶实对称矩阵, 它们的特征值 $>1$. 试证: $AB$ 的特征值的绝对值 $>1$.
461 0
[Everyday Mathematics]20150222
设 $$\bex a_0=1,\quad a_1=\frac{1}{2},\quad a_{n+1}=\frac{na_n^2}{1+(n+1)a_n}\ (n\geq 1). \eex$$ 试证: $\dps{\sum_{k=0}^\infty\frac{a_{k+1}}{a_k}}$ 收敛, 并求其值.
687 0
[Everyday Mathematics]20150204
设 $k_0>0$, $\phi:[k_0,\infty)\to[0,\infty)$ 是有界递减函数, 并且 $$\bex \phi(k)\leq \frac{A}{(k-h)^\al}\phi(h)^\beta,\quad k>h>k_0, \eex$$ 其中 $A,\al>0$, $0h>k_0.
675 0