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代表星期一,B代表星期二……G代表星期天)。注意,这里一定要是【相同位置】,我一开始用map来找第一个相同字母和第二个相同字母,但是测试点1 2 4一直过不了,后来才看到,题目要求的是相同位置且字母相同……
- 在前两个字符串中到第二个相同位置的相同字母或数字(AN或09),找到之后,它作为小时;
- 在最后两个字符串找到第一个相同位置的字母(大小写字母都可),找到之后,它作为分钟。
【坑点】
- 时钟和分钟如果不是两位数,都需要补“0”补到两位数。
代码
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
string a, b, c, d, result;
cin>>a>>b>>c>>d;
int minlen = min(a.length(), b.length());
int cnt = 0;
for(int i=0;i<minlen;i++){
if(a[i]==b[i]&&b[i]>='A'&&b[i]<='G'&&cnt==0){
int weekday = b[i]-'A'+1;
if(weekday==1) result += "MON ";
else if(weekday==2) result += "TUE ";
else if(weekday==3) result += "WED ";
else if(weekday==4) result += "THU ";
else if(weekday==5) result += "FRI ";
else if(weekday==6) result += "SAT ";
else if(weekday==7) result += "SUN ";
cnt++;
}
else if(a[i]==b[i]&&(b[i]>='A'&&b[i]<='N'||b[i]>='0'&&b[i]<='9')&&cnt==1){
int hour = 0;
if(b[i]>='0'&&b[i]<='9') hour = b[i]-'0';
else if(b[i]>='A'&&b[i]<='N') hour = b[i]-'A'+10;
if(hour>=0&&hour<=9) result += "0" + to_string(hour);
else result += to_string(hour);
result += ":";
break;
}
}
minlen = min(c.length(), d.length());
for(int i=0;i<minlen;i++){
if(c[i]==d[i]&&(c[i]>='a'&&c[i]<='z'||c[i]>='A'&&c[i]<='Z')){
if(i>=0&&i<=9) result += "0" + to_string(i);
else result += to_string(i);
break;
}
}
cout<<result;
return 0;
}