您的位置:首页 > 其它

1061. Dating (20)

2015-11-27 13:55 351 查看
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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>

#define Maxn 62
const char week[7][4] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};

char input1[Maxn];
char input2[Maxn];
char input3[Maxn];
char input4[Maxn];

int main(void)
{
scanf("%s",input1);
scanf("%s",input2);
scanf("%s",input3);
scanf("%s",input4);
int length1 = strlen(input1);
int length2 = strlen(input2);
int length3 = strlen(input3);
int length4 = strlen(input4);

int i;
for(i=0;i<length1&&i<length2;++i)
{
if((input1[i] == input2[i] )&& ('A' <= input1[i] && input1[i] <='G'))
{
printf("%s ",week[input1[i] - 'A']);
break;
}
}
for(i=i+1;i<length1&&i<length2;++i)
{
if(input1[i] == input2[i] && ( ( isdigit(input1[i]) || ('A' <= input1[i] && input1[i] <= 'N') )) )
{
if(isdigit(input1[i]))
{
printf("%02d:",input1[i] - '0');
}
else
{
printf("%02d:",input1[i]-'A'+10);
}
break;
}
}

for(i=0;i<length3&&i<length4;++i)
{
if((input3[i] == input4[i] )&& isalpha(input3[i]))
{
printf("%02d",i);
break;
}
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: