The topics are as follows:
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 is actually referring to the coded time "Thursday 14:0 4 "--since the first common capital 中文版 (case sensitive) shared by the first and strings is the 4th capital Le Tter ' 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 + a D Ay is represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the Chinese letter gkfx by the last of the strings is ' s ' at the 4th position, representing the 4th minute. Now given and pairs of strings, you is supposed to help Sherlock decode the dating time.
Input Specification:
Each input file contains the one test case. Each case gives 4 non-empty strings of no more than, characters without white space in 4 lines.
Output Specification:
For each test case, print the decoded time on one line, in the format ' Day hh:mm ', where ' Day ' is a 3-character abbreviati On for the days in a week--that's, ' 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, the result is a unique for each case.
Sample Input:
3485djdkxh4hhge 2984AKDFKKKKGGEDSB S&HGSFDK d&hyscvnm
Sample Output:
THU 14:04
The title requires finding the earliest common characters in the previous two strings, the first common character is a~g, representing Monday to Sunday, and the second for 0~9, a~n for 0-23 hours.
Find the position of the first common letter in the latter two strings as a minute.
The code is as follows:
#include <iostream> #include <stdio.h> #include <map> #include <string>using namespace Std;char * weeks[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};int Char2hour (char c) {if (c >= ' 0 ' && C <= ' 9 ') { Return C-' 0 '; }else{return C-' A ' + 10; }}int Char2week (char c) {return C-' A ';} int main () {string str1,str2,str3,str4; CIN >> str1 >> str2 >> str3 >> STR4; int datacnt = 0; int len1 = min (Str1.length (), str2.length ()); for (int i = 0; i < len1; i++) {char C1 = str1[i]; char C2 = str2[i]; if (c1 = = C2) {if (datacnt = = 0) {//Find week. A ~ G if (C1 >= ' A ' && C1 <= ' G ') {printf ("%s", Weeks[char2week (C1)]); datacnt++; }}else{//Find hour if ((C1 >= ' 0 ' && C1 <= ' 9 ') | | (C1 >= ' A ' && C1 <= ' N ')) {printf ("%02d: ", Char2hour (C1)); Break }}}} int len2 = min (Str3.length (), str4.length ()); for (int i = 0; i < len2; i++) {char C1 = str3[i]; char C2 = str4[i]; if (c1 = = C2 && isalpha (C1)) {printf ("%02d\n", I); Break }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
1061. Dating (20)