• A1061. Dating


    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 #include<cstdio>
     2 #include<iostream>
     3 #include<string.h>
     4 using namespace std;
     5 char date[8][4] = {" ", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
     6 int w2num(char e){
     7     if(e >= '0' && e <= '9')
     8         return e - '0';
     9     else return e - 'A' + 10;
    10 }
    11 int isw(char a){
    12     return a >= 'a' && a <= 'z' || a >= 'A' && a <= 'Z';
    13 }
    14 int main(){
    15     char str[4][61], ch1 = '', ch2;
    16     int count = 0;
    17     for(int i = 0; i < 4; i++)
    18         scanf("%s", str[i]);
    19     for(int i = 0; i < strlen(str[0]) ; i++){
    20         if(ch1 == '' && str[0][i] == str[1][i] && str[0][i] >= 'A' && str[0][i] <= 'G'){
    21             ch1 = str[0][i];
    22             continue;
    23         }
    24         if(ch1 != '' && str[0][i] == str[1][i] && ((str[0][i] >= '0' && str[0][i] <= '9') || (str[0][i] >= 'A' && str[0][i] <= 'N'))){
    25             ch2 = str[0][i];
    26             break;
    27         }
    28     }
    29     for(count = 0; str[2][count] != '' && str[3][count] != ''; count++)
    30         if(str[2][count] == str[3][count] && isw(str[2][count]))
    31             break;
    32     printf("%s %02d:%02d", date[ch1 - 'A' + 1], w2num(ch2), count);
    33     cin >> ch1;
    34     return 0;
    35 }
    View Code

    1、第一个星期,选取的是同下标的、大写字母在A-G上的相同字母;第二个小时,是同下标、大写字母在A到N或者是数字的相同字符;第三个分钟是相同字母的下标。容易忽略的是星期的大写字母只有7个,小时的大写字母只有14个。

  • 相关阅读:
    第四章 变量的三大特征,垃圾回收机制,可变类型和不可变类型的简单表述
    第三章 有关变量的理解
    第二章 编程语言的分类及优缺点的分析
    IIS拓展访问的文件格式
    JS之HTTP请求
    HTTP请求
    HtmlAgilityPack解析html
    支付宝支付功能开发
    Web.config配置ActiveReports
    数据库连接字符串
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/8439556.html
Copyright © 2020-2023  润新知