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
代码长度限制
16 KB
时间限制
200 ms
内存限制
64 MB
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string a,b,c,d;
cin >> a >> b >> c >> d;
string week[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
string res;
for(int i = 0,cnt = 0; i < min(a.length(),b.length()); i++){
if(a[i] == b[i] && a[i] >= 'A' && a[i]<='G' && cnt == 0){
cout << week[a[i]-'A'] + ' ';
cnt++;
continue;
}
if(a[i] == b[i] && cnt == 1){
if(a[i] >= '0' && a[i]<= '9') {
cout << '0' << a[i] << ':';
break;
}
else if(a[i] >= 'A' && a[i] <= 'N') {
cout << a[i]- 'A' + 10 << ':';
break;
}
}
}
for(int i = 0; i < min(c.length(),d.length()); i++){
if(c[i]==d[i]&&(c[i]>='a'&&c[i]<='z'||c[i]>='A'&&c[i]<='Z')){
if(i<9) cout << '0' << i;
else cout << i;
break;
}
}
return 0;
}
总结
1. 扣条件就完事了
文章提供了一个关于如何从给定的四个字符串中解码出日期和时间的问题。SherlockHolmes接收到的字符串包含编码信息,通过找到共同的首字母来确定星期几、小时和分钟。给定两个字符串对,程序需要找出对应的时间。输入和输出格式都有详细说明,代码示例用C++编写,用于解决这个问题。

被折叠的 条评论
为什么被折叠?



