1061 Dating (20point(s))
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
题目大意:
设计思路:
- 确定星期几:第一个和第二个字符串中第一次字母相同,范围是 A-G;
- 确定小时数:满足条件 1 后,继续在后续字符串中查找,范围是 0-9 和 A-N;条件 2 满足后即可跳出循环,以防止输出再次满足条件的信息;
- 确定分钟数:第三和第四个字符串第一次字母相同,范围 A-Z 和 a-z;
- 小时和分钟要补零
编译器:C (gcc)
#include <stdio.h>
#include <string.h>
int main(void)
{
char week[7][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
char s1[100], s2[100], s3[100], s4[100];
int d, h, m;
int i, j, len;
scanf("%s%s%s%s", s1, s2, s3, s4);
len = ((i = strlen(s1)) < (j = strlen(s2))) ? i : j;
for (i = 0; i < len; i++) {
if (s1[i] == s2[i] && (s1[i] >= 'A' && s1[i] <= 'G')) {
d = s1[i] - 'A';
break;
}
}
for (i = i + 1; i < len; i++) {
if (s1[i] == s2[i]) {
if (s1[i] >= 'A' && s1[i] <= 'N') {
h = s1[i] - 'A' + 10;
break;
}
if (s1[i] >= '0' && s1[i] <= '9') {
h = s1[i] - '0';
break;
}
}
}
len = ((i = strlen(s3)) < (j = strlen(s4))) ? i : j;
for (i = 0; i < len; i++) {
if (s3[i] == s4[i] && ((s3[i] >= 'a' && s3[i] <= 'z') || (s3[i] >= 'A' && s3[i] <= 'Z'))) {
m = i;
break;
}
}
printf("%s %02d:%02d", week[d], h, m);
return 0;
}