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

PAT B1014/A1061 Dating

时间:2019-08-25 19:37:38      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:cti   set   letter   位置   ast   kkk   amp   sunday   and   

PAT B1014/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 /****************************************************
 2 PAT B1014/A1061 Dating
 3 ****************************************************/
 4 #include <iostream>
 5 #include <iomanip>
 6 #include <vector>
 7 #include <string>
 8 
 9 using namespace std;
10 
11 const string DAY_IN_WEEK[7] = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
12 
13 int main() {
14     vector<string> dateInfo(4);
15 
16     for (int i = 0; i < 4; ++i) {
17         cin >> dateInfo[i];
18     }
19 
20     //星期
21     int i = 0;
22     for (; i < dateInfo[0].size() && dateInfo[1].size(); ++i) {
23         if (dateInfo[0][i] == dateInfo[1][i] && dateInfo[0][i] >= A && dateInfo[0][i] <= G) {
24             cout << DAY_IN_WEEK[dateInfo[0][i] - A] <<  ;
25             break;
26         }
27     }
28 
29     //小时
30     //上个循环中找到之后直接break,此处++i是从上一个循环的下一个位置开始
31     for (++i; i < dateInfo[0].size() && dateInfo[1].size(); ++i) {   
32         if (dateInfo[0][i] == dateInfo[1][i]) {
33             if (dateInfo[0][i] >= 0 && dateInfo[0][i] <= 9) {
34                 cout << 0 << dateInfo[0][i];
35                 break;
36             }
37             else if (dateInfo[0][i] >= A && dateInfo[0][i] <= N) {
38                 cout << dateInfo[0][i] - A + 10;
39                 break;
40             }
41         }
42     }
43 
44     //分钟
45     for (i = 0; i < dateInfo[2].size() && i < dateInfo[3].size(); ++i) {
46         if (dateInfo[2][i] == dateInfo[3][i]) {
47             if (dateInfo[2][i] >= a && dateInfo[2][i] <= z ||
48                 dateInfo[2][i] >= A && dateInfo[2][i] <= Z) {
49                 cout << : << setw(2) << setfill(0) << i;
50                 break;
51             }
52         }
53     }
54 
55     return 0;
56 }

注意事项:

  无。

 

PAT B1014/A1061 Dating

标签:cti   set   letter   位置   ast   kkk   amp   sunday   and   

原文地址:https://www.cnblogs.com/mrdragon/p/11408808.html

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