pat 甲级 训练真题集 1061! 1061. Dating (20)

1061. Dating (20)

​ 时间限制

​ 150 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

大的东西就不说了只记录下需要注意的点

第一个相同的大写字母大的范围需控制在[A,Z]第二个需控制在[A,N]

判断分钟时需注意只能为字母利用isalpha

代码如下:

#include<iostream>
#include<cctype>
#include<cstring>
using namespace std;
char days[8][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
void print_day(char a){
	int i=a-'A';
	printf("%s ",days[i]);
}
void print_hour(char a){
	int i;
	if(isdigit(a)){
		i=a-'0';
	}else{
		i=a-'A'+10;
	}
	if(i==0)printf("00:");
	else if(i<10)printf("0%d:",i);
	else printf("%d:",i);
}
int main(){
	char a[65],b[65],c[65],d[65];
	scanf("%s%s%s%s",a,b,c,d);
	int flag=0;
	char day,hour;
	int m;
	for(int i=0,j=0;i<strlen(a)&&j<strlen(b);++i,++j){
		if(a[i]==b[i]&&(a[i]>='A'&&a[i]<='G')){		
			if(flag==0){
				day=a[i];
				flag=1;
				continue;
			}
		}
		if(flag==1){
			if(a[i]==b[i]&&((a[i]>='A'&&a[i]<='N')||isdigit(a[i]))){
				hour=a[i];
				break;
			}
		}
	}
	for(int i=0,j=0;i<strlen(c)&&j<strlen(d);++i,++j){
		if(c[i]==d[i]&&isalpha(c[i])){
			m=i;
			break;
		}
	}
	print_day(day);
	print_hour(hour);
	if(m==0)printf("00");
	else if(m<10)printf("0%d",m);
	else printf("%d",m);
	return 0;
}