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

    题目大意:

    福尔摩斯接到一张奇怪的字条:“我们约会吧!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

  • 相关阅读:
    Js将字符串转换成对象或数组en
    iview渲染函数
    iview中render函数监听事件
    Arduino Nano 读取ADS1100实例
    Raspberry Pi 3 安装 Lazarus 1.6.2(2017-02-09更新)
    Lazarus for Raspbian安装
    Delphi xe7 FireMonkey / Mobile (Android, iOS)生成 QR Code完整实例
    Delphi xe7 up1 调用android振动功能
    Delphi xe7 android实现透明度可以调整的对话框
    delphi XE7 在Android编译SharedActivity时出错
  • 原文地址:https://www.cnblogs.com/moonlight1999/p/15606404.html
Copyright © 2011-2022 走看看