zoukankan      html  css  js  c++  java
  • PAT(A) 1061. Dating (20)

    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
    
    #include <cstdio>
    #include <cstring>
    /*
    输入4个字符串(长度<=60)
    day: 前两个字符串第一对相同位置的A~G(星期一到天)范围的大写字母
    hh: day位置之后第一对相同位置的0~9, A~N(24个小时)范围的字符
    mm: 后两个字符串的第一对相同位置的A~Z, a~z范围的英文字母所在该字符串中的位置
    输出约会时间(题目保证每个测试存在唯一解)
    */
    
    int main()
    {
        char day[7][5]={"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
        char str1[70], str2[70], str3[70], str4[70];
        /*
        FILE *fp;
        fp=fopen("test.txt", "r");
        fgets(str1, 70, fp);
        fgets(str2, 70, fp);
        fgets(str3, 70, fp);
        fgets(str4, 70, fp);
        //fscanf(fp, "%s%s%s%s", str1, str2, str3, str4);     //会出错!
        */
        gets(str1);
        gets(str2);
        gets(str3);
        gets(str4);
        int len1=strlen(str1);
        int len2=strlen(str2);
        int len3=strlen(str3);
        int len4=strlen(str4);
    
        int i;  //day和hh都在str1,str2中找,故i控制两次查找
        
        //步骤(1): 寻找str1和str2中第一对相同位置的大写字母(A~G)
        for(i=0; i<len1 && i<len2; i++){
            if(str1[i]==str2[i] && str1[i]>='A' && str1[i]<='G'){
                printf("%s ", day[str1[i]-'A']);    //输出对应的星期几
                break;
            }
        }
        //步骤(2): 在上面的基础上,往后寻找相同位置的0~9, A~N范围的字符
        for(i++; i<len1 && i<len2; i++){
            if(str1[i]==str2[i]){
                if(str1[i]>='0' && str1[i]<='9'){
                    //printf("%02d", str1[i]-'0');   //法一:%02d 输出两位整数,不够前面补0
                    printf("0%c:", str1[i]);         //法二:按字符方式
                    break;
                }
                else if(str1[i]>='A' && str2[i]<='N'){
                    printf("%02d:", str1[i]-'A'+10);     //输出10~23
                    break;
                }
            }
        }
        //步骤(3): 寻找str3和str4中第一对相同位置的A~Z或a~z范围的英文字母
        for(i=0; i<len3 && i<len4; i++){
            if(str3[i]==str4[i]){
                if( (str3[i]>='A' && str3[i]<='Z') || (str3[i]>='a' && str3[i]<='z') ){
                    printf("%02d", i);      //输出当前位置
                    break;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    Docker Mysql 只从复制
    Mysql 常用sql记录
    ssh 内网穿透
    MyBatis相关记录
    mybatis(plus) 继承子模块的 Mapper文件
    Navicat 连接 Mysql 错误 2059
    angular service 进行组件通信
    angular 中的 ? 和 !
    angular @Input() 和 @Output()
    Centos7 安装 Docker CE
  • 原文地址:https://www.cnblogs.com/claremore/p/6548381.html
Copyright © 2011-2022 走看看