PAT A1061 Dating (20 minutes)

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

Meaning of the questions:

Given a string 4:
For the first two strings, the first occurring for the same capital letters (AG) represents Monday to Sunday, the same second character (0-9 || AN) denotes hours;
for after two strings, a first pair of occurrences of the letter (az || AZ) represented minutes.

Ideas:

(1) takes a two-dimensional array of characters stored date of day;
(2) Before traversing the two strings, the output of the first date of the same capital letter (AG) represented by the same characters and the second pair (0-9 | | the AN) expressed hour;
minutes (3) traversing two strings, the output of the first pairs of letters (az || AZ) represents.

Code:

#include<cstdio>
char day[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
char hh[24][3]={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};//int型不能赋值08、09,因为C++中数字0开头表示八进制数,故采用char型 
int main(){
	char a1[61],a2[61],b1[61],b2[61];
	scanf("%s%s%s%s",a1,a2,b1,b2);
	int i;
	for(i=0;i<60;i++){
		if(a1[i]==a2[i]&&a1[i]>='A'&&a1[i]<='G'){
			printf("%s ",day[a1[i]-'A']);
			break;
		}
	}
	for(++i;i<60;i++){
		if(a1[i]==a2[i]&&((a1[i]>='A'&&a1[i]<='N')||(a1[i]>='0'&&a1[i]<='9'))){
			if(a1[i]>='0'&&a1[i]<='9'){
				printf("%s:",hh[a1[i]-'0']);//也可采用下方 %02d 的方式直接输出a1[i]-'0' 
				break;
			}
			else{
				printf("%s:",hh[a1[i]-'A'+10]);
				break;
			}
		}
	}
	for(int j=0;j<60;j++){
		if(b1[j]==b2[j]&&((b1[j]>='a'&&b1[j]<='z')||(b1[j]>='A'&&b1[j]<='Z'))){
			printf("%02d",j);//数值长度不足2位就补0输出,但不影响长度超过2位的数值输出 
			break;
		} 
	}
	return 0;
}

vocabulary:

strange odd
coded encoded
common capital English letter capital letters common
case sensitive to the case of sensitive
shared shared, common
decode coded
abbreviation omitted, Acronym

Published 26 original articles · won praise 0 · Views 480

Guess you like

Origin blog.csdn.net/PanYiAn9/article/details/102633382