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

PAT1061:Dating

时间:2017-10-14 21:55:48      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:str   因此   min   class   repr   文本对比   文本   char   val   

1061. Dating (20)

时间限制
150 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

思路
字符串处理问题,根据题目要求处理好就行,比较考验细心和耐心。
注意第一个字母的范围在A到G7个字母内(代表一周七天),第二个相同的字符是0到9以及A到N(10点到23点)。第三个字符是另外两个字符串共有的相同位置的英文字符。
最后的输出要转换成时间形式,因此要注意0到9的数字需要用00到09这样的形式表示。

代码
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

vector<string> week = {"MON","TUE","WED","THU","FRI","SAT","SUN"};

int main()
{
   string s1,s2,s3,s4;
   while(cin >> s1 >> s2 >> s3 >> s4)
   {
       int len1 = min(s1.size(),s2.size()),len2 = min(s3.size(),s4.size());
       vector<int> key(3);
       int i = 0;
       for(;i < len1; i++)
       {
           if(s1[i] == s2[i] && (s1[i] >= A && s1[i] <=G))
           {
               key[0] = s1[i] - A;
               break;
           }
       }

       for(int j = i + 1;j < len1;j++)
       {
           if(s1[j] == s2[j])
           {
               if(s1[j] <= 9 && s1[j] >= 0)
               {
                  key[1] = s1[j] - 0;
                  break;
               }
               else if(s1[j] >= A && s1[j] <= N)
               {
                   key[1] = s1[j] - A + 10;
                   break;
               }
           }
       }

       for(int j = 0; j < len2;j++)
       {
           if(s3[j] == s4[j] &&((s3[j] >= a && s3[j] <= z) || (s3[j] >= A && s3[j] <= Z)))
           {
                key[2] = j;
                break;
           }
       }

      cout << week[key[0]] << " " ;
      if(key[1] < 10)
        cout << "0" << key[1] <<":";
      else
        cout << key[1] << ":";
      if(key[2] < 10)
        cout <<"0" << key[2] << endl;
      else
        cout << key[2] << endl;
   }
}

PAT1061:Dating

标签:str   因此   min   class   repr   文本对比   文本   char   val   

原文地址:http://www.cnblogs.com/0kk470/p/7668641.html

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