PAT Level B | 1014 Sherlock Holmes's Date (20 points)

Detective Holmes received a strange note: Let’s date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. The detective quickly understood that the strange garbled characters on the note are actually the date at 14:04 on Thursday, because the first pair of the same uppercase English letter in the first two strings (case distinguished) is the fourth letter D , Represents Thursday; the second pair of identical characters is E, which is the 5th English letter, which represents the 14th hour of the day (so the number 0 to 9 from 0 o’clock to 23 o’clock of the day, and capital letters A to N Means); the same English letter s of the first pair of the following two strings appears in the fourth position (counting from 0), representing the fourth minute. Now given two pairs of strings, please help Holmes to decode the date of the appointment.

Input format:

Enter 4 strings that are not empty, contain no spaces, and whose length does not exceed 60 in 4 lines.

Output format:

Output the appointment time in one line, the format is DAY HH:MM, where DAY is the 3-character abbreviation of a week, that is, MON means Monday, TUE means Tuesday, WED means Wednesday, THU means Thursday, FRI means Friday, SAT means Saturday , SUN means Sunday. Question input guarantees that each test has a unique solution.

Input sample:

3485djDkxh4hhGE 
2984akDfkkkkggEdsb 
s&hgsfdk 
d&Hyscvnm

Sample output:

THU 14:04

Idea: This question looks very simple, but there are actually many pitfalls. It should be noted that when looking for the day of the week, the search is in uppercase letters, and the range is between A and G. There is also a range when looking for hours, and a size when looking for minutes. You can write letters.

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main()
{
    
    
    string l[4];
    string week[7]={
    
    "MON","TUE","WED","THU","FRI","SAT","SUN"};	//星期几
    string time="0123456789ABCDEFGHIJKLMN";	//小时
    int pos1,pos2,pos3;	//位置
    for(int i=0;i<4;i++)
        getline(cin,l[i]);
	for(int i=0;i<l[0].size();i++)
		if(isupper(l[0][i])&&l[0][i]>='A'&&l[0][i]<='G'&&l[0][i]==l[1][i]){
    
    
			pos1=i;
			break;
		}
	cout <<week[l[0][pos1]-'A']<<" ";
	for(int i=pos1+1;i<l[0].size();i++)
		if(l[0][i]==l[1][i]&&(isdigit(l[0][i])||l[0][i]>='A'&&l[0][i]<='N')){
    
    
			pos2=i;
			break;
		}
	for(int i=0;i<l[3].size();i++)
		if(isalpha(l[3][i])&&l[3][i]==l[2][i]){
    
    
			pos3=i;
			break;
		}
	printf("%02d:%02d",time.find(l[0][pos2]),pos3);
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44888152/article/details/108629509