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,0~9,A~N,不分大小写。
给出四个字符串,前两个字符串确定日期和小时, 后两个字符串确定分钟;
日期:前两个字符串第一个相等的大写字母(位置相同,字母相同)A~G 分别表示星期一到星期天
小时:在找到日期的字符串后面继续查找,找到第一个相同的数字或字母(0~9,A~N)(位置也要相同),分别表示0~23
分钟:在后面两个字符串中查找,第一个相等的字母,不分大小写, 字母相等的位置就是分钟
题解:
这里用cctype中的isalpha(),isdigit()判断字符是否为字母,或者数字。也可以用不等式来判断
AC代码:
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
char a[65],b[65];
string week[]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(){
cin>>a>>b;
string wk;
int hh,mm;
int f=0;
int la=strlen(a),lb=strlen(b);
for(int i=0;i<min(la,lb);i++){
if(f&&((a[i]>='A' && a[i]<='N')||(a[i]>='0' && a[i]<='9'))&&a[i]==b[i]){
if(a[i]>='A' && a[i]<='N') {
hh=a[i]-'A'+10;
break;
}
else {
hh=a[i]-'0';
break;
}
}
if(!f&&a[i]>='A' && a[i]<='G' &&a[i]==b[i]){
f=1;
wk=week[a[i]-'A'];
}
}
memset(a,' ',sizeof(a));
memset(b,' ',sizeof(b));
cin>>a>>b;
la=strlen(a);
lb=strlen(b);
for(int i=0;i<min(la,lb);i++){
if(isalpha(a[i])&& a[i]==b[i]) {
mm=i;
break;
}
}
printf("%s %02d:%02d",wk.c_str(),hh,mm);
return 0;
}