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
Meaning of the questions:
Topic not read ah, the original position should be the same. . . Range is also not clear, is A ~ G, 0 ~ 9, A ~ N, not case-sensitive.
Given four strings, the first two character string specifying the date and hour, the two strings is determined min;
Date: The first two strings equal to the first capital letter (same position with the same letter) A ~ G, respectively represents Monday through Sunday
hours: continue to look after the date string is found, to find the first one and the same number or letter (0 ~ 9, a ~ N ) ( also the same position), each represent 0 to 23
min: in Finding two rear strings, a first letter equal, regardless of the case, is equal to the position of letters min
answer:
Cctype used here in isalpha (), isdigit () determines whether the character is a letter or a number. It may be determined by an inequality
AC Code:
#include<iostream> #include<string> #include<cstring> #include<algorithm> using namespace std; char a[65],b[65]; string week[]={"MON","TUE","WED","THU","FRI","SAT","SUN"}; cinmain () {int>>a>>b; string wk; int hh,mm; int f=0; int la=strlen(a),lb=strlen(b); for(int i=0;i<min(la,lb);i++){ if(f&&((a[i]>='A' && a[i]<='N')||(a[i]>='0' && a[i]<='9'))&&a[i]==b[i]){ if(a[i]>='A' && a[i]<='N') { hh=a[i]-'A'+10; break; } else { hh=a[i]-'0'; break; } } if(!f&&a[i]>='A' && a[i]<='G' &&a[i]==b[i]){ f=1; wk=week[a[i]-'A']; } } memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); cin>>a>>b; la=strlen(a); lb=strlen(b); for(int i=0;i<min(la,lb);i++){ if(isalpha(a[i])&& a[i]==b[i]) { mm=i; break; } } printf("%s %02d:%02d",wk.c_str(),hh,mm); return 0; }