PAT甲级——A1061 Dating
Posted zzw1024
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT甲级——A1061 Dating相关的知识,希望对你有一定的参考价值。
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
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 6 string date[7] = "MON","TUE","WED","THU","FRI","SAT","SUN" ; 7 string s1, s2, s3, s4; 8 cin >> s1 >> s2 >> s3 >> s4; 9 int flag = 0; 10 for (int i = 0; i < s1.length() && i<s2.length(); ++i) 11 12 if (flag == 0 && s1[i] >= ‘A‘ && s1[i] <= ‘Z‘ && s1[i] == s2[i]) 13 14 cout << date[s1[i] - ‘A‘] << " "; 15 flag = 1; 16 17 else if(flag == 1 && s1[i] == s2[i] && ((s1[i] >= ‘A‘ && s1[i] <= ‘Z‘) || (s1[i] >= ‘0‘ && s1[i] <= ‘9‘))) 18 19 if (s1[i] >= ‘0‘&& s1[i] <= ‘9‘) 20 cout << "0" << s1[i] - ‘0‘ << ":"; 21 else 22 cout << (s1[i] - ‘A‘ + 10) << ":"; 23 break; 24 25 26 int k = 0; 27 for (int i = 0; i < s3.length() && i < s4.length(); ++i) 28 29 if (((s3[i] >= ‘a‘ && s3[i] <= ‘z‘) || (s3[i] >= ‘A‘ && s3[i] <= ‘Z‘)) && s3[i] == s4[i]) 30 31 k = i; 32 break; 33 34 35 cout << (k > 9 ? "" : "0") << k << endl; 36 return 0; 37
以上是关于PAT甲级——A1061 Dating的主要内容,如果未能解决你的问题,请参考以下文章