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
#include<iostream>
using namespace std;
int is_hour(char a)
{
if(a>='0'&&a<='9')
return 1;
if(a>='A'&&a<='N')
return 2;
return 0;
}
bool is_minute(char a)
{
if(a>='a'&&a<='z')
return true;
if(a>='A'&&a<='Z')
return true;
return false;
}
int main()
{
string s1,s2,s3,s4;
cin>>s1>>s2>>s3>>s4;
//寻找第一二对字符串里的第一个相同的大写字母,计算周几
int i;
char week[8][5]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
string day;
for(i=0;i<s1.size()&&i<s2.size();i++)
{
if(s1[i]==s2[i]&&s1[i]>='A'&&s1[i]<='G')
{
day=week[int(s1[i]-'A')];
break;
}
}
//寻找第一二对字符串里第二个相同的合法字符,计算小时数
int hour;
for(i+=1;i<s1.size()&&i<s2.size();i++)
{
if(s1[i]==s2[i]&&is_hour(s1[i]))
{
hour=is_hour(s1[i])==1?int(s1[i]-'0'):int(s1[i]-'A'+10);
break;
}
}
//寻找第三四对字符串里第一个相同的合法字符,计算分钟数
int minute;
for(i=0;i<s3.size()&&i<s4.size();i++)
{
if(s3[i]==s4[i]&&is_minute(s3[i]))
{
minute=i;
break;
}
}
cout<<day;
printf(" %02d:%02d\n",hour,minute);
}
通过输入的四个字符串来判断约会的时间。
第一个时间是星期几。是通过第一个字符串和第二个字符串对比,第一个相同的大写英文字母(区分大小写,而且必须是A-G),A代表周一,B代表周二,以此类推。
第二个时间是第几个小时。也是通过前两个字符串对比,第二个相同的字符(前提是数字0~9,或者字母A~N),代表小时数,0代表0点,1代表一点,A代表10点,B代表11点,以此类推。
第三个时间是分钟数。是通过后两个字符串对比,第一个相同的英文字符所处的数组的下标(注意是从0开始)是几,就代表第几分钟。
这题其实没什么算法,就是麻烦,要搞清楚每一个时间的具体情况。