1061 Dating(20 分)
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
解题思路:直接模拟就好了,只要注意最后输出的格式就好了%02d,不够的就用0填充
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string w[]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main(void)
{
string a,b,c,d;
cin>>a;getchar();
cin>>b;getchar();
cin>>c;getchar();
cin>>d;
int j,pos,k;
for(int i=0;i<a.size()&&i<b.size();i++)
{
if(a[i]==b[i]&&a[i]>='A'&&a[i]<='G')
{
j=i;
break;
}
}
for(int i=j+1;i<a.size()&&b.size();i++)
{
if(a[i]==b[i]&&((a[i]>='A'&&a[i]<='N')||isdigit(a[i])))
{
k=i;
break;
}
}
for(int i=0;i<c.size()&&i<d.size();i++)
{
if(c[i]==d[i]&&(isalpha(c[i])))
{
pos=i;
break;
}
}
cout<<w[a[j]-'A'];
int m;
if(isalpha(a[k])) m=a[k]-'A'+10;
else m=a[k]-'0';
printf(" %02d:%02d\n",m,pos);//注意格式
return 0;
}
博客围绕一道20分的题目展开,讲述Sherlock Holmes根据奇怪字符串解码约会时间。题目给出输入输出规范及示例,解题思路是直接模拟,需注意输出格式用%02d,不够的用0填充。
&spm=1001.2101.3001.5002&articleId=82082203&d=1&t=3&u=dbf5c8c8298742f9808ff62faa4e33f4)
416

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



