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
类型:字符串处理
题目大意:给出两对字符串,根据要求输出一个日期
分析:这个题目最大的难度来源于审题,把题目读明白了,也就没啥难度了;说实在的题目说的还蛮坑的;首先,题目中说的common capital English letter,不仅要是相同的大写字母,而且字母在字符串中的下标还要一样;其次就是字符的范围;在求星期几的时候,字母只能是大写的A-G;在求小时的时候,只能是0-9,A-N;在求分钟的时候,只能是a-z, A-Z,因为他说了是the English letter;
#include<iostream>
#include<string>
using namespace std;
string days[] = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
int main(){
string a,b,c,d;
cin >> a >> b >> c >> d;
int la = a.length(),lb = b.length();
int lc = c.length(),ld = d.length();
char C[3];
int index = -1;
for (int i = 0; i<la && i<lb; i++){
if (a[i] >= 'A' && a[i] <= 'G'){
if (a[i] == b[i]){
C[0] = a[i];
index = i;
break;
}
}
}
for (int i = index + 1; i<la && i<lb; i++){
if ((a[i] >= 'A'&&a[i] <= 'N') || (a[i] >= '0'&&a[i] <= '9')){
if (a[i] == b[i]) {
C[1] = a[i];
break;
}
}
}
int mi = -1;
for (int i = 0; i<lc && i<ld; i++){
if (((c[i] >= 'a'&& c[i] <= 'z') || (c[i] >= 'A'&& c[i] <= 'Z')) && c[i] == d[i]){
mi = i;
break;
}
}
string day = days[C[0] - 'A'];
int hour = C[1] >= '0'&& C[1] <= '9' ? C[1] - '0' : 10 + C[1] - 'A';
printf("%s %02d:%02d", day.c_str(), hour, mi);
return 0;
}