题目:
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
题意:
给你四个字符串,其中字符串中不包含空格;
(1)在前两个字符串中,第一个相等的大写的英文字母确定是星期几,第二个相等的字符确定小时;
(2)后两个字符串中,第一个相等的字符的位置(从0开始)确定分钟;
(3)对于星期几的输出是英语星期几的前三个字母(大写);
思路:
(1)在前两个字符串中找出来第一个相等的字符(字符范围是'A'--'G' ,注意是大写的,否则最后一个测试数据会错);
(2)在前两个字符串中找出来第二个相等的字符确定小时(一定要在第一个字符没有找过的范围内进行查找第二个相等的字符,字符的范围是‘0’--‘9’||‘A'--'N');
(3)在后两个字符串中找出来第一个相等字符的位置(位置从0开始,注意相等的字符是英文字符,包括大小写,区分大小写);
(4)注意输出的格式,星期几就输出前三个大写字母,后面一个空格;时间是24计时法,注意输出要占用两位数,不够的要补0;
代码如下:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[101],b[101],c[101],d[101];
char x,y;
int z;
void print()
{
if(x=='A')
printf("MON");
else if(x=='B')
printf("TUE");
else if(x=='C')
printf("WED");
else if(x=='D')
printf("THU");
else if(x=='E')
printf("FRI");
else if(x=='F')
printf("SAT");
else if(x=='G')
printf("SUN");
printf(" ");
int k;
if(y>='0'&&y<='9')
k=y-'0';
else
k=y-'A'+10;
printf("%02d:",k);
printf("%02d\n",z);
return ;
}
int main()
{
while(~scanf("%s%s%s%s",a,b,c,d))
{
int la=strlen(a);
int lb=strlen(b);
int lc=strlen(c);
int ld=strlen(d);
int l=min(la,lb);
int ll=min(lc,ld);
int i,j;
for(i=0; i<l; i++)
{
if(a[i]>='A'&&a[i]<='G')
{
if(a[i]==b[i])
{
x=a[i];
break;
}
}
}
for(j=i+1; j<l; j++)
{
if((a[j]>='0'&&a[j]<='9')||(a[j]>='A'&&a[j]<='N'))
{
if(a[j]==b[j])
{
y=a[j];
break;
}
}
}
for(int i=0; i<ll; i++)
{
if(c[i]>='a'&&c[i]<='z'||c[i]>='A'&&c[i]<='Z')
{
if(c[i]==d[i])
{
z=i;
break;
}
}
}
print();
}
return 0;
}