1061 Dating (20分)
作者:CHEN, Yue
单位:浙江大学
代码长度限制:16 KB
时间限制:400 ms
内存限制:64 MB
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
题意:
找第一对字符串中的第一组相等的大写字母,从大写字母后再找一对0-9,A-N的字符。在第二对字符中中找第一对英文字符。
思路:
遍历。
参考代码:
#include <iostream>
#include <cstring>
using namespace std;
char week[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main() {
char str[4][60];
int i;
for(i=0;i<4;i++)scanf("%s",str[i]);
int len=min(strlen(str[0]),strlen(str[1]));
for(i=0;i<len;i++){
if(str[0][i]>='A'&&str[0][i]<='G'){
if(str[0][i]==str[1][i]){
printf("%s ",week[str[0][i]-'A']);
break;
}
}
}
for(i++;i<len;i++){
if(str[0][i]==str[1][i]){
if(isdigit(str[0][i])){
printf("0%c",str[0][i]);
break;
}else if(str[0][i]>='A'&&str[0][i]<='N'){
printf("%02d",str[0][i]-'A'+10);
break;
}
}
}
for(i=0;i<min(strlen(str[2]),strlen(str[3]));i++){
if(str[2][i]>='a'&&str[2][i]<='z'||str[2][i]>='A'&&str[2][i]<='Z')
if(str[2][i]==str[3][i]){
printf(":%02d",i);
break;
}
}
return 0;
}
如有错误,欢迎指正