zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    快速排序算法
    学习了几天的jQuery Mobile的一点感受
    jQuery Mobile 图标无法显示
    html5基础知识
    百度地图与谷歌地图 (常识、区别,更倾向于使用百度地图,纠错信息比谷歌多)
    (转)百度Map API
    历年软件设计师下午考试试题汇总统计
    HTML5的本地存储
    EnterpriseArchitectect 软件的勾选的几个选项对应的中文意思
    访问权限控制表
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12831452.html
Copyright © 2011-2022 走看看