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.
解答:这道题真的超级水。。因为没理解好题意被坑了好多时间。好吧,因为它的题目意思暗含:Day的范围是['A', 'G'],在做题时应作为条件;Hour的范围是:[0,9]U['A', 'N'],也应作为条件;Min的条件是isalpha。
AC代码如下:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cctype>
using namespace std;
char day[7][5] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int main()
{
string s1, s2, s3, s4;
char d, h;
int m;
bool flag = false;
cin >> s1 >> s2 >> s3 >> s4;
for(int i = 0; i < s1.size() && i < s2.size(); ++i)
{
if( (isdigit(s1[i]) || 'A' <= s1[i] && s1[i] <= 'N') && s1[i] == s2[i] && flag == true)
{
h = s1[i]; break;
}
if( 'A' <= s1[i] && s1[i] <= 'G' && s1[i] == s2[i] && flag == false )
{
d = s1[i];
flag = true;
}
}
for(int i = 0; i < s3.size() && i < s4.size(); ++i)
{
if(isalpha(s3[i]) && s3[i] == s4[i])
{
m = i;
break;
}
}
printf("%s ", day[d - 'A']);
printf("%02d:", isdigit(h) ? h - '0' : h - 'A' + 10);
printf("%02d\n", m);
return 0;
}