1061 Dating (20 point(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
简单字符串处理。注意题目的隐含条件!可以使用STL的unordered_map<char,int>、isalpha()等简化代码。
#include<iostream>
#include<string>
using namespace std;
string weekday[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(void){
int w,h,m;
string s1,s2;
cin>>s1>>s2;
int cnt=0;
for(int i=0;i<s1.length()&&i<s2.length();i++){
if(s1[i]==s2[i]){
if(cnt==0&&s1[i]>='A'&&s1[i]<='G'){
w = s1[i]-'A';
cnt++;
}
else if(cnt==1&&((s1[i]>='0'&&s1[i]<='9')||(s1[i]>='A'&&s1[i]<='N'))){
if(s1[i]>='0'&&s1[i]<='9') h = s1[i]-'0';
else h = 10+s1[i]-'A';
break;
}
}
}
cin>>s1>>s2;
for(int i=0;i<s1.length()&&i<s2.length();i++){
if(s1[i]==s2[i]&&((s1[i]>='A'&&s1[i]<='Z')||(s1[i]>='a'&&s1[i]<='z'))){
m = i;break;
}
}
printf("%s %02d:%02d\n",weekday[w].c_str(),h,m);
return 0;
}
学习大神的STL使用:https://blog.youkuaiyun.com/richenyunqi/article/details/79503640
本文介绍了一种通过解析特殊字符串来解码隐藏的约会时间的方法。利用字符在字符串中的共同出现,将特定的字符映射到一周中的某天、小时和分钟,最终输出格式化的日期时间。
8371

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



