1014 Holmes dating (C language)

Sherlock Holmes received a strange note: 我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnmdetective soon understood, strange gibberish is actually dating the time 14:04 on Thursday note, because the front two in the first string for the same capital letters ( differentiated case) is the first four letters D, representing Thursday; the same character a second pair is E, it is the first five letters of the alphabet, the representative day of 14 hours (day and then 0:00 to 23:00 by a numbers 0 to 9, and the capital letters a represents N); 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 formats:

4 are given in the input line 4 non-empty, without a space, 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

General idea is to use a character array to store the input password, then traverse requires two string comparison, according to the subject of the request to record the corresponding data. Since beginning to write programs, so the code may not be conducive to reading, here try to show their ideas.

Pit Summary:

  • Is the number of hours the same character a second time, the first time must be the same capital letters, to a corresponding output date. Here I used a flag to mark the same many times.
  • Second question format output error when looking for a quite a while to find out, as is the number of minutes or hours to single digits when the need to use 0xthis way to output
  • Then it should be noted that, where the date is subject to a 大写字母number of hours given topic is 相同的字符so numbers are possible. Subject to a number of minutes英文字母
  • There is a small mistake in a few hours when the time to write a digital output directly, then look for a half-day error, but later found not converted to digital, and digital format needs to be 0-9 times 0xto have to pay attention to this output

continueIt is a good thing. Need multi-purpose use, of course, sometimes the cycle have been only one case out of the loop direct result of the need for special handling, sometimes planted on top of.

#include<stdio.h>
#include<string.h>
int main()
{
    char str[4][61];
    int i;
    char Day[][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    for(i=0;i<4;i++){
        scanf("%s",&str[i]);
    }
    int flag=2;                    //区分小时数和日期,来控制循环
    int mlen= strlen(str[0]) > strlen(str[1]) ?strlen (str[1]) : strlen(str[0]);
    for(i=0; i<mlen; i++){
        if(str[0][i] == str[1][i]  && str[0][i]>=65){  //大于A
            if(flag==2 && str[0][i]<=71){             //小于G
                flag--;
                printf("%s ",Day[str[0][i]-65]);
                continue;
            }
            if(flag==1 && str[0][i]<=78){            //小于N
                printf("%d:",str[0][i]-65+10);
                break;
            }
        }
        else if(str[0][i] == str[1][i] && str[0][i]>=48 && str[0][i]<=57 &&flag==1){    //‘0’-‘9’
            printf("%02d:",str[0][i]-48);  //因为字符串数组中的数字也是以ASCII码来存储的,
            break;                         //所以想要输出数字就得转换一下  
        }
    }
    int mlen2= strlen(str[2]) > strlen(str[3]) ?strlen (str[3]) : strlen(str[2]);
    for(i=0;i<mlen2;i++){
        if(str[2][i]==str[3][i] &&  ( (str[2][i]>=97 &&str[2][i]<=122) || (str[2][i]>=65 &&str[2][i]<=90))){
            printf("%02d",i);           //'a'-'z'    ||  'A'-'Z'
            break;
        }
    }
    return 0;
}
Released five original articles · won praise 0 · Views 57

Guess you like

Origin blog.csdn.net/Czrobe/article/details/104910251