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
代码:
连题目都看不懂,要怎么和Sherlock约会啊?!!(摔
#include<stdio.h>
#include<string.h>
int main()
{
char s1[100],s2[100],s3[100],s4[100];
scanf("%s%s%s%s",s1,s2,s3,s4);
char week[7][5] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
int i,len1 = strlen(s1),len3 = strlen(s3);
for(i=0;i<len1;i++)
{
//大于小于不能连写 a<=x<=b×
//一周只有7天,所以是A-G而不是A-Z
if(s1[i]==s2[i]&&s1[i]<='G'&&s1[i]>='A')
{
//A-'A'=0,根据题意本应+1表示第一个字母,但数组需要-1,正好抵掉
printf("%s ",week[s1[i]-'A']);
break;
}
}
//在第一个相同字母后的位置接着搜索
for(i++;i<len1;i++)
{
if(s1[i]==s2[i])
{
if(s1[i]>='0'&&s1[i]<='9')
{
printf("%02d:",s1[i]-'0');
break;
}
else if(s1[i]<='N'&&s1[i]>='A')
{
//A~N表示10-23
printf("%02d:",s1[i]-'A'+10);
break;
}
}
}
for(i=0;i<len3;i++)
{
// A-Z 65-90 | a-z 97-122
if(s3[i]==s4[i]&&(s3[i]>='a'&&s3[i]<='z'||s3[i]>='A'&&s3[i]<='Z'))
{
//%2d右对齐,%02d右对齐补零
printf("%02d",i);
break;
}
}
}