1014 Holmes appointment (20 minutes)
Sherlock Holmes received a strange note: we meet it! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s & hgsfdk d & Hyscvnm. Detective soon realized that actually strange garbled appointments on time Thursday 14:04 note, because the front two in the first string for the same capital letters (case sensitive distinction) is the first four letters D representative Thursday; 2 is the E of the same character, it is the first five letters of the alphabet, the representative day of 14 hours (so one is 0:00 to 23:00 by the numbers 0 to 9, and the capital letters a to N shown); behind the first two for the same string of letters s appear in the 4th position (counting from 0), the representative of the first 4 minutes. Now given two pairs of strings, please help Holmes decoded appointment time.
Input format:
Input line 4 are given in the four non-empty, no spaces, and the length of the string 60 is not exceeded.
Output formats:
Output appointment time in a row, the format DAY HH: MM, which is a week DAY 3 character abbreviation that MON = Monday, TUE for Tuesday, WED for Wednesday, THU expressed Thursday, FRI means that on Friday, SAT for Saturday, SUN for Sunday. Enter the topic guarantee the existence of a unique solution for each test.
Sample input:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
Sample output:
THU 14:04
124 test points wrong answer, looked a long time, and finally changed out, the original is guilty of a stupid mistake, not the digital exchange value of the ASCII code numbers (count hours of code, line 25) ¯ □ ¯ ||
This many pits questions, pay attention to the point I do not want to talk about, seen a lot of big brothers code, feel written very lengthy, it needs to be raised, can pointer familiar with the pointer, it can greatly simplify the amount of code.
#include <stdio.h>
int main()
{
int d,b=0,m,h;
char a[4][61];
for(int i=0;i<4;i++)
gets(a[i]);
for(int j=0;j<60;j++)
{
if(a[0][j]>='A' && a[0][j]<='G' && a[1][j]==a[0][j] && b==0)
{
d=a[0][j]-'A'+1;
b++;
continue;
}
if(b==1 && a[1][j]==a[0][j] )
{
if(a[0][j]>='A' && a[0][j]<='N')
{
h=a[0][j]-'A'+10;
break;
}
if(a[0][j]>='0' && a[0][j]<='9')
{
h=a[0][j]-'0';
break;
}
}
}
for(int k=0;k<60;k++)
{
if( (a[2][k]>='A' && a[2][k]<='Z') || (a[2][k]>='a' && a[2][k]<='z') && a[2][k]==a[3][k])
{
m=k;
break;
}
}
switch(d)
{
case 1:printf("MON ");break;
case 2:printf("TUE ");break;
case 3:printf("WED ");break;
case 4:printf("THU ");break;
case 5:printf("FRI ");break;
case 6:printf("SAT ");break;
case 7:printf("SUN ");break;
}
printf("%02d:%02d\n",h,m);
return 0;
}
/*测试点124答案错误,看了半天,终于改出来了,原来是犯了低级错误,没把数字的ASCII码换回数字的数值(算小时的代码里,第25行) ̄□ ̄||*/
/*注意的点我不想讲了,看了很多大佬的代码,感觉自己写得很冗长,有待提高吧,对指针熟悉的可以用指针,可以大大简化代码量。*/