PAT 1061 Dating[简单]

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.

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-G分别表示周一-周日;0-23时,使用0-9+A-N表示;

 使用后两个字符串的相同位置的小写字母的位置下标来表示分钟数。

//猛一看感觉还是挺简单的。 

#include <iostream>
#include <map>
#include<cstdio>
using namespace std;

int main() {
    map<char,string> week;
    string w[]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    for(int i=0;i<7;i++){
        week['A'+i]=w[i];
    }
    map<char,int> hour;
    for(int i=0;i<24;i++){
        if(i<=9)
            hour[i+'0']=i;
        else
            hour['A'+i-10]=i;
    }
    string s1,s2,s3,s4;
    cin>>s1>>s2>>s3>>s4;
    int len1=s1.size(),len2=s2.size();
    int len3=s3.size(),len4=s4.size();
    bool wk=false;
    for(int i=0;i<len1&&i<len2;i++){
        if(!wk){
            if(s1[i]>='A'&&s1[i]<='G'&&s1[i]==s2[i]){
                cout<<week[s1[i]]<<" ";//现在星期找到了。
                wk=true;
            }
        }else if(s1[i]==s2[i]){
            if(isdigit(s1[i])||(s1[i]>='A'&&s1[i]<='N')){
                printf("%02d:",hour[s1[i]]);break;//找到了之后就break,不然之后会有相等的。
            }

        }
    }
    for(int i=0;i<len3&&i<len4;i++){
        if(s3[i]==s4[i]&&isalpha(s3[i])){
            printf("%02d",i);break;
        }
    }
    return 0;
}

//注意在小时数找到之后就立马break,而不是还要循环,因为后面还有可能有相等的,应该break掉。

1.注意map的使用,总的来说还是挺简单的~

猜你喜欢

转载自www.cnblogs.com/BlueBlueSea/p/9569388.html