zoukankan      html  css  js  c++  java
  • 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

    题目要求从前两个字符串中找出最早出现的公共字符,第一个公共字符为A~G,代表星期一到星期日;第二个为0~9、A~N代表0~23小时。

    在后两个字符串中找出第一个公共字母的位置,作为分钟。

    代码如下:

    #include <iostream>
    #include <stdio.h>
    #include <map>
    #include <string>
    
    using namespace std;
    
    char* weeks[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
    
    int char2hour(char c){
        if(c >= '0' && c <= '9'){
            return c - '0';
        }else{
            return c - 'A' + 10;
        }
    
    }
    
    int char2week(char c){
        return c - 'A';
    }
    
    int main()
    {
        string str1,str2,str3,str4;
        cin >> str1 >> str2 >> str3 >> str4;
        int dataCnt = 0;
        int len1 = min(str1.length(),str2.length());
        for(int i = 0; i < len1; i++){
            char c1 = str1[i];
            char c2 = str2[i];
            if(c1 == c2){
                if(dataCnt == 0){ // find week. A ~ G
                    if(c1 >= 'A' && c1 <= 'G'){
                        printf("%s ",weeks[char2week(c1)]);
                        dataCnt++;
                    }
                }else{ // find hour
                    if((c1 >= '0' && c1 <= '9') || (c1 >= 'A' && c1 <= 'N')){
                        printf("%02d:",char2hour(c1));
                        break;
                    }
                }
            }
        }
        int len2 = min(str3.length(),str4.length());
        for(int i = 0; i < len2; i++){
            char c1 = str3[i];
            char c2 = str4[i];
            if(c1 == c2 && isalpha(c1)){
                printf("%02d
    ",i);
                break;
            }
        }
        return 0;
    }
    


  • 相关阅读:
    Lock、synchronized和ReadWriteLock,StampedLock戳锁的区别和联系以及Condition
    Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十一):集成 Shiro 框架
    Spring Cloud之路:(七)SpringBoot+Shiro实现登录认证和权限管理
    XSS过滤JAVA过滤器filter 防止常见SQL注入
    shiro jwt 构建无状态分布式鉴权体系
    JSON Web Token 入门教程
    C#实现WinForm DataGridView控件支持叠加数据绑定
    C#实现WinForm窗体逐渐显示效果
    定义通用的可通过lambda表达式树来获取属性信息
    C#实现通用数据过滤窗体
  • 原文地址:https://www.cnblogs.com/aiwz/p/6154101.html
Copyright © 2011-2022 走看看