• 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

    题目大意:

    福尔摩斯接到一张奇怪的字条:“我们约会吧!3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母D,代表星期四;第2对相同的字符是E,那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母s出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,要求解码得到约会的时间~

    分析:

    按照题目所给的方法找到相等的字符后判断即可,如果输出的时间不足2位数要在前面添0,即用%02d输出~
    原文链接:https://blog.csdn.net/liuchuo/article/details/51985845

    题解

    细节决定成败~

    #include <bits/stdc++.h>
    
    using namespace std;
    string s[7]= {"MON","TUE","WED","THU","FRI","SAT","SUN"};
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif
        string a,b,c,d;
        cin>>a>>b>>c>>d;
        int len=min(a.length(),b.length());
        int i;
        for(i=0; i<len; i++)
        {
            char x=a[i],y=b[i];
            if(x==y&&x>='A'&&x<='G')
            {
                cout<<s[x-'A']<<" ";
                break;
            }
        }
        for(int j=i+1; j<len; j++)
        {
            char x=a[j],y=b[j];
            if(x==y&&x>='A'&&x<='N')
            {
                printf("%02d:",x-'A'+10);
                break;
            }
            if(x==y&&x>='0'&&x<='9')
            {
                printf("%02d:",x-'0');
                break;
            }
        }
        int len1=min(c.length(),d.length());
        for(i=0; i<len1; i++)
        {
            char x=c[i],y=d[i];
            if(x==y&&isalpha(x)&&isalpha(y))
            {
                printf("%02d",i);
                break;
            }
        }
        return 0;
    }
    

    本文来自博客园,作者:勇往直前的力量,转载请注明原文链接:https://www.cnblogs.com/moonlight1999/p/15606404.html

  • 相关阅读:
    利用Multipeer Connectivity框架进行WiFi传输
    iOS 8创建交互式通知
    iOS开发网络篇—文件的上传
    iOS开发网络篇—发送GET和POST请求(使用NSURLSession)
    iOS之深入了解控制器View的加载
    工厂模式三部曲:工厂方法模式
    iOS web与js的简单交互
    精心整理的十个必须要知道CSS+DIV技巧
    [JQuery代码]超酷鼠标滑过背景高亮效果
    10个可以直接拿来用的JQuery代码片段
  • 原文地址:https://www.cnblogs.com/moonlight1999/p/15606404.html
Copyright © 2020-2023  润新知