1014 Sherlock Holmes' appointment (20 points)

Sherlock Holmes received a strange note:

let's date! 
3485djDkxh4hhGE 
2984akDfkkkkggEdsb 
s&hgsfdk 
d&Hyscvnm

The detective soon understood that the strange random code on the note was actually the date time at 14:04 on Thursday, because the first pair of the same uppercase English letters (case sensitive) in the first two strings was the fourth letter   D. On behalf of Thursday; The second pair of identical characters is   E  , That is the fifth English letter, which represents the 14th hour of the day (so the numbers 0 to 9 and capital letters from 0 to 23 o'clock of the day)   A   reach   N   Means); The first pair of identical English letters in the last two strings   s   Appears on the 4th position (counting from 0), representing the 4th minute. Given two pairs of strings, please help Holmes decode the date.

Input format:

Input four non empty strings with no spaces and a length of no more than 60 in each of the four lines.

Output format:

Output the appointment time in one line in the format   DAY HH:MM, where   DAY   Is a 3-character abbreviation for a week, i.e   MON   Means Monday, TUE   It means Tuesday, WED   Means Wednesday, THU   Means Thursday, FRI   Means Friday, SAT   Means Saturday, SUN   Means Sunday. Topic input ensures that each test has a unique solution.

Input example:

3485djDkxh4hhGE 
2984akDfkkkkggEdsb 
s&hgsfdk 
d&Hyscvnm

No blank lines at the end

Output example:

THU 14:04

Solution idea: in the process of doing this problem, I felt that because the topic was not so clear, and I saw the pass rate of this problem, the consideration of this problem was too complex. The topic did not make it clear whether the result existed in the first line or in the second line. When I started, I thought of A more comprehensive situation, Maybe if there is A date in the second line, I will start the whole program in an all-round way. The title doesn't say that the letters of his date are from A to G. I'm still taking into account the situation of Z. this messy wrong idea is that the whole program has somehow become so large, but I have to say that there are fewer and fewer bugs in the program now. Come on

It is always darkest before dawn

//The meaning of this question seems quite complicated, but it's not so complicated in fact
//Find the date and hour in the first two lines and the minute in the next line. Here, pay attention to which line is the first and which line is the last
#include<iostream>
#include<string>
#include<vector>
#include<cctype>
using namespace std;

int swaps(string a, string b)
{
	if (a.size() > b.size()) {
		return 1;
	}
	else
		return 0;
}

int main()
{
	vector<string>arr(4);//The input must be four strings
	for (int i = 0; i < 4; ++i)
	{
		cin >> arr[i];
	}
	int mide = -1;
	mide = swaps(arr[0], arr[1]);
	if (mide == 1)
	{
		string middle;
		middle = arr[0];
		arr[0] = arr[1];
		arr[1] = middle;
	}
	mide = -1;
	mide = swaps(arr[2], arr[3]);//This is to make the first row of comparison the smallest
	if (mide == 1)
	{
		string middle;
		middle = arr[2];
		arr[2] = arr[3];
		arr[3] = middle;
	}
	string Day[8] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };//The day of the week is stored here
	char hour[24] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N' };
	//int min = 0;// Used to record minutes
	int flag = 0;//It is used to record whether you are looking for days, hours or minutes. The title does not say where these three things appear, so use this to count the number. I guess this is the difficulty of this question
	for (int i = 0; i < arr[0].size(); ++i)
	{
		if (arr[0][i] == arr[1][i])
		{
			if ((flag == 0) && (isupper(arr[0][i])))//If you're looking for days
			{
                if(arr[0][i]<='G')
                {
				    flag++;
				    int middle = toupper(arr[0][i]) - 'A';//Here, you need to convert this element to uppercase. toupper() can convert uppercase letters to uppercase letters. If they were originally uppercase letters, the original number will be returned
				    middle = middle % 7;
				    cout << Day[middle] << " ";//Output days here
                }
			}
			else if ((flag == 1) && ((arr[0][i]>='0')&&(arr[0][i]<='9')||((arr[0][i]>='A')&&(arr[0][i]<='N'))))
			{
                flag++;
				char middle;
				if (isalpha(arr[0][i]))
					middle = arr[0][i];
				else
					middle = arr[0][i];
				for (int j = 0; j < 24; ++j)
				{
					if (middle == hour[j])
					{
                        if(j<10)
						    cout <<"0"<< j << ":";//The output hours are judged here
                        else
                            cout << j << ":";
						break;
					}
				}
			}
			else if ((flag == 2) && (isalpha(arr[0][i])))
			{//What we're dealing with here is minutes
                flag++;
				if (i < 10) {
					cout << "0" << i;
					return 0;
				}
				else
				{
					cout << i;
					return 0;
				}
			}
		}
	}
	for (int i = 0; i < arr[2].size(); ++i)
	{
		if (arr[2][i] == arr[3][i])
		{
            
			if ((flag == 0) && (isupper(arr[2][i])))//If you're looking for days
			{
                if(arr[2][i]<='G')
                {
				    flag++;
				    int middle = toupper(arr[2][i]) - 'A';//Here, you need to convert this element to uppercase. toupper() can convert uppercase letters to uppercase letters. If they were originally uppercase letters, the original number will be returned
				    middle = middle % 7;
				    cout << Day[middle] << " ";//Output days here
                }
			}
			else if((flag == 1) && ((arr[2][i]>='0')&&(arr[2][i]<='9')||((arr[2][i]>='A')&&(arr[2][i]<='N'))))
			{
                flag++;
				char middle;
				if (isalpha(arr[2][i]))
					middle = arr[2][i];
				else
					middle = arr[2][i];
				for (int j = 0; j < 24; ++j)
				{
					if (middle == hour[j])
					{
                        if(j<10)
						    cout <<"0"<< j << ":";//The output hours are judged here
                        else
                            cout << j << ":";
						break;
					}
				}
			}
			else if ((flag == 2) && (isalpha(arr[2][i])))
			{//What we're dealing with here is minutes
                flag++;
				if (i < 10) {
					cout << "0" << i;
					return 0;
				}
				else
				{
					cout << i;
					return 0;
				}
			}
		}
	}
	return 0;
}

 

Tags: Programming Algorithm

Posted on Thu, 25 Nov 2021 21:12:47 -0500 by il_cenobita