【PAT】1061. Dating (20)

题目描述

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.

翻译:夏洛克福尔摩斯接到一条包含一些奇怪字符串的消息:“让我们约会吧!3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。他仅仅花了一分钟就算出这些奇怪的字符串实际上代表着用密文表示的时间 “Thursday 14:04” – 由于前两个字符串的第一个公共大写字母是第四个大写字母‘D’,代表一个星期的第四天;第二对相同的字母是第五个大写字母‘E’,代表第14小时(假设时间为0-23一天,分别用0-9和A-N表示);第二对字符串的第一对相同字母为第4位置的‘s’,代表第4分钟。现在给你两对字符串,你需要帮助夏洛克破解出约会时间。

INPUT FORMAT

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.

翻译:每个输入文件包含一组测试数据。对于每组输入数据,4行内给出4个非空的不含空格的不超过60个字符的字符串。

OUTPUT FORMAT

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.

翻译:对于每组测试数据,输出一行破译时间,以”DAY HH:MM”的格式,“DAY”为一周内每一天的3位缩写-“MON”代表星期一,“TUE”代表星期二,“WED”代表星期三,“THU”代表星期四,“FRI”代表星期五,“SAT”代表星期六,“SUN”代表星期天。数据保证结果唯一。


Sample Input:

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

Sample Output:

THU 14:04


解题思路

这道题先得看懂题目,发现是W是第一对字符串的第一对相同的大写字母,H是第一对字符串的第二对相同的字符,M是第二对字符串第一对相同的字母的位置。然后,第一对是‘A’-‘G’,第二对是‘0’-‘9’+‘A’-‘N’,我还以为只有大写字母呢。第三对只能是字母,这个倒是能看出来。剩下的就是模拟了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#define INF 99999999
using namespace std;
char Week[7][5]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int D,H,M;
int main(){
    string a[2],b[2];
    cin>>a[0]>>a[1];
    int length=min(a[0].size(),a[1].size());
    int flag=0;
    for(int i=0;i<length;i++){
        if(flag==2)break;
        if(a[0][i]==a[1][i]){
            if(flag==0&&a[0][i]>='A'&&a[0][i]<='G'){
                D=a[0][i]-'A';
                flag++;
                continue;
            }
            if(flag==1){
                if(a[0][i]>='A'&&a[0][i]<='N')H=a[0][i]-'A'+10,flag++;
                else if(a[0][i]>='0'&&a[0][i]<='9')H=a[0][i]-'0',flag++;
                else continue;
            }
        }
    }
    cin>>b[0]>>b[1];
    length=min(b[0].size(),b[1].size());
    for(int i=0;i<length;i++){
        if(b[0][i]==b[1][i]&&((b[0][i]>='A'&&b[0][i]<='Z')||(b[0][i]>='a'&&b[0][i]<='z'))){
            M=i;
            break;
        }
    }   
    printf("%s %02d:%02d\n",Week[D],H,M);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值