1061 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.

非常好的题目,使我cpu旋转

一开始看英文题目,看得似懂非懂,无法下手。然后找到B级的中文题目,终于是看懂了意思,但是中文的题目也表述的非常模糊,主要有以下几个注意点:

1、星期几的信息来自前两个字符串的第一个相同的大写字母,并且范围是'A'-'G',在写代码时要限定清楚,并不是第一个所有的大写字母得出序号再模7,不然测试点4过不去;

2、几点钟的信息,题目要求的是第二个相同的字符,事实上应该是在第一个相同的大写字母之后的第一个相同的字符,而不是从头开始的第二个相同的字符。

题目出得很好,下次不要再出了。

#include<iostream>
#include<cstring>

int convert(char ch)
{
    if(ch>='0'&&ch<='9')
        return ch-'0';
    else if(ch>='A'&&ch<='N')
        return ch-'A'+10;
    else
        return -1;
}

int main()
{
    char str[4][61];
    char week[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    scanf("%s\n%s\n%s\n%s",str[0],str[1],str[2],str[3]);
    int length = strlen(str[0]);
    char key[3];
    int count=0;
    for(int i=0;i<length;i++)
    {
        if(str[0][i]==str[1][i])
        {
            if(count==0)
            {
                if(str[0][i]>='A'&&str[0][i]<='G')
                {       
                    key[count++]=str[0][i];
                }
            }
            else if(count==1)
            {
                if((str[0][i]>='0'&&str[0][i]<='9')||(str[0][i]>='A'&&str[0][i]<='N'))
                {
                    key[count++]=str[0][i];
                    break;
                }
            }
        }
    }
    length = strlen(str[2]);
    for(int j=0;j<length;j++)
    {
        if(str[2][j]==str[3][j])
        {
            if((str[2][j]>='A'&&str[2][j]<='Z')||(str[2][j]>='a'&&str[2][j]<='z'))
            {
                key[2]='0'+j;
                break;
            }
        }
    }
    printf("%s %02d:%02d", week[key[0]-'A'], convert(key[1]), key[2]-'0');

    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值