• 1061 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

    题意:

      在前两个字符串中找出天数,和小时数。在后两个字符串中找出分钟数。天数所对应的是(‘A’ - ‘G’),小时数所对应的是(0-9 ‘A’ - ‘N’)所以不能单纯的用isupper()来判断,分钟数所对应的时第三组和第四组字符串中第一个相等英文字符的下标。

    思路:

      模拟。

    Code:

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 int main() {
     6     string str1, str2, str3, str4;
     7     cin >> str1 >> str2 >> str3 >> str4;
     8     string week[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
     9     int i = 0, j = 0, hour;
    10     string day;
    11     while (i < str1.length() && i < str2.length()) {
    12         if (str1[i] == str2[i] && (str1[i] >= 'A' && str1[i] <= 'G')) {
    13             day = week[str1[i] - 'A'];
    14             break;
    15         }
    16         i++;
    17     }
    18     i = i + 1;
    19     while (i < str1.length() && i < str2.length()) {
    20         if (str1[i] == str2[i]) {
    21             if (str1[i] >= 'A' && str1[i] <= 'N') {
    22                 hour = str1[i] - 'A' + 10;
    23                 break;
    24             } else if (isdigit(str1[i])) {
    25                 hour = str1[i] - '0';
    26                 break;
    27             }
    28         }
    29         i++;
    30     }
    31     while (j < str3.length() && j < str4.length()) {
    32         if (str3[j] == str4[j] && isalpha(str3[j])) break;
    33         j++;
    34     }
    35     cout << day;
    36     printf(" %02d:%02d
    ", hour, j);
    37     return 0;
    38 }
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    如何设置'REUSE_ALV_GRID_DISPLAY'的单个单元格的颜色
    ABAP绘图功能模块概观(转)
    [数据库基础]——编码标准之编码注意事项(持续更新)
    ABAP--关于ABAP流程处理的一些命令的说明(stop,exit,return,check,reject)
    ABAP中的Table Control编程
    ABAP中的数据校验-备注
    ABAP 一个隐藏 selection-screen block的实例
    ABAP语言常用的系统字段及函数
    ABAP中的同步和异步调用
    FOR ALL ENTRIES IN 与 INNER JOIN 写在一个SQL上影响效率
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12831452.html
Copyright © 2020-2023  润新知