1061. Dating (20)

1.根据给出的规则对string进行匹配解密。

2.第一对string中,DAY的char需要限制在A到G之间,一个星期只有7天;HOUR的char需要限制在A到N,0到9之间,这样才是合理的0~23小时

3.之前卡在了没有限制HOUR的char需要限制在A到N,0到9之间。

时间限制
50 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

 
AC代码:

//#include<string>
//#include<stack>
//#include<unordered_set>
//#include <sstream>
//#include "func.h"
//#include <list>
#include <iomanip>
#include<unordered_map>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include <algorithm>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
#include<stack>
using namespace std;
 
 
 
int main(void)
{
    string num2Day[] = { "", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
    string first1, first2, second1, second2;
    //getline(cin, first1);
    //getline(cin, first2);
    //getline(cin, second1);
    //getline(cin, second2);
    cin >> first1>> first2>> second1>> second2;
    char dayChar = -1;
    char hourChar = -1;
    for (int i = 0; i < min(first1.size(), first2.size()); i++)
    {
        if (first1[i] == first2[i] &&( (first1[i] >= 'A'&&first1[i] <= 'N') || (first1[i] >= '0'&&first1[i] <= '9')))
        {//需要限制在A到N,0到9之间,这样才是合适的0~23小时显示,否则会出现测试点不过
            if (dayChar == -1 && (first1[i] >= 'A'&&first1[i] <= 'N'))
                dayChar = first1[i];
            else if (dayChar != -1)
            {
                hourChar = first1[i];
                break;
            }
        }
    }
    int mm;
    for (int i = 0; i < min(second1.size(), second2.size()); i++)
    {
        if (second1[i] == second2[i] && ((second1[i] >= 'A'&&second1[i] <= 'Z') || (second1[i] >= 'a'&&second1[i] <= 'z')))
        {
            mm = i;
            break;
        }
    }
    string day = num2Day[dayChar - 'A' + 1];
    string hour = "";
    int hourInt;
    if (hourChar >= 'A'&&hourChar <= 'Z')
        hourInt = hourChar - 'A' + 10;
    else
        hourInt = hourChar - '0';
    char c = hourInt / 10 + '0';
    hour += c;
    c = hourInt % 10 + '0';
    hour += c;
    cout << day << " " << hour;
    printf(":%02d\n", mm);
 
 
    return 0;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注