我是靠谱客的博主 痴情歌曲,最近开发中收集的这篇文章主要介绍PAT1061:Dating1061. Dating (20),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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;
   }
}

转载于:https://www.cnblogs.com/0kk470/p/7668641.html

最后

以上就是痴情歌曲为你收集整理的PAT1061:Dating1061. Dating (20)的全部内容,希望文章能够帮你解决PAT1061:Dating1061. Dating (20)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部