题目链接:点击打开链接
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&HyscvnmSample Output:
THU 14:04这题后来在乙级考试里重新出现过。
我的C++程序:
#include<iostream>
#include<string>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
int i = 0;
string s1, s2, s3, s4;
char week_sign,hour_sign;//week_sign第一对相同的大写字母代表星期,hour_sign代表小时的字符
int minute=0;//分钟
map<char, string>week;//星期几
map<char,int>hour;//小时
week['A'] = "MON";week['B'] = "TUE";week['C'] = "WED";week['D'] = "THU";
week['E'] = "FRI";week['F'] = "SAT";week['G'] = "SUN";//从星期一到星期日
hour['A'] = 10;hour['B'] = 11;hour['C'] = 12;hour['D'] = 13;hour['E'] = 14;
hour['F'] = 15;hour['G'] = 16;hour['H'] = 17;hour['I'] = 18;hour['J'] = 19;
hour['K'] = 20;hour['L'] =21;hour['M'] =22;hour['N'] =23;//从10小时到23小时
cin >> s1 >> s2 >> s3 >> s4;//接受四个字符串
int length = (s1.size() > s2.size() )? s2.size() : s1.size();//length是s1,s2里最短的字符长度
for (i=0;i <length;i++)//得到代表星期几的大写字符
{
if (s1[i]>= 'A'&&s1[i]<= 'G'&&s1[i]==s2[i])//字符必须是大写字母
{
week_sign= s1[i];
s1[i]= '@';
break;//找到第一个就跳出循环
}
}
for (;i < length;i++)//计算代表小时的字符
{
if (s1[i] == s2[i])
{
if (s1[i] >= '0'&&s1[i] <= '9')//'0'<=小时字符<='9'
{
hour_sign = s1[i];
break;
}
if(s1[i] >= 'A'&&s1[i] <= 'N')//大写字母A-N表示10-23小时
{
hour_sign = s1[i];
break;
}
}
}
length= (s3.size() > s4.size()) ? s4.size() : s3.size();//length是s3,s4里最短的字符长度
for (i=0;i <length;i++)//计算分钟
{
if (s3[i] >= 'A'&&s3[i] <= 'z'&&s3[i] == s4[i])//分钟字符必须为为大写或小写字母,不是数字
{
minute =i;
break;
}
}
cout << week[week_sign] <<' ';//输出星期
if (hour_sign >= '0'&&hour_sign <= '9')
cout << 0 << hour_sign;
else
cout << hour[hour_sign];//输出小时
cout<<':';
cout << setw(2) << setfill('0') << minute;//输出两位的分钟,不足用0补满
//system("pause");
return 0;
}