1061 Dating (20 分)

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

题目大意:
给定四个字符串,要求从中找到代表约会时间的三个信息day、hour、minute

算法分析:
用s存储四个字符串信息,按照要求依次遍历寻找,注意不要下标越界,注意每个信息都有限定的字符。

一个疑惑:不知DEVC中为何不能用min函数

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int day,hour,minute,flag=0;
	string mm[7]= {
    
    "MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
	string s[4];//存储四个字符串 
	for(int i=0;i<4;i++)
	cin>>s[i];
	for(int i=0;i<s[0].size()&&i<s[1].size();i++){
    
    
		if(s[0][i]==s[1][i]&&s[0][i]>='A'&&s[0][i]<='G'){
    
    
			day=s[0][i]-'A'+1;
			for(int j=i+1;j<s[0].size()&&i<s[1].size();j++){
    
    
				if(s[0][j]==s[1][j]&&(s[0][j]>='0'&&s[0][j]<='9')){
    
    
				//注意代表可能是数字字符,也可能是字母 
					hour=s[0][j]-'0';
					flag=1;
				}
				if(s[0][j]==s[1][j]&&(s[0][j]>='A'&&s[0][j]<='N')){
    
    
					hour=s[0][j]-'A'+10;
					flag=1;
				}
				if(flag==1)
				break;
			}
		}
		if(flag==1)
		break;
	}
	for(int i=0;i<s[2].size()&&i<s[3].size();i++){
    
    
		if(s[2][i]==s[3][i]&&isalpha(s[2][i])){
    
    
			minute=i;
			break;
		}
	}
	cout<<mm[day-1];
	printf("%02d:%02d",hour,minute);
}

猜你喜欢

转载自blog.csdn.net/weixin_48954087/article/details/114377468