码迷,mamicode.com
首页 > 其他好文 > 详细

PAT甲级——A1061 Dating

时间:2019-08-03 14:22:55      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:kkk   stream   letter   ios   name   ida   lan   cout   more   

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

标签:kkk   stream   letter   ios   name   ida   lan   cout   more   

原文地址:https://www.cnblogs.com/zzw1024/p/11294526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!