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

考察内容是字符串处理。
这是很久之前的写法。

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char ans1[100],ans2[100],ans3[100],ans4[100];
    const char week[7][7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    cin.get(ans1,100);
    getchar();
    cin.get(ans2,100);
    getchar();
    cin.get(ans3,100);
    getchar();
    cin.get(ans4,100);
    getchar();
//  printf("%s",ans1);
    int len1=strlen(ans1);
    int len2=strlen(ans2);
    int len3=strlen(ans3);
    int len4=strlen(ans4);
    int i;
    for(i = 0;i<len1&&i<len2;i++)
    {
        if(ans1[i]==ans2[i]&&ans1[i]>='A'&&ans1[i]<='G')
        {
            printf("%s ",week[ans1[i]-'A']);break;
        }
    }
    for(i++;i<len1&&i<len2;i++)
    {
        if(ans1[i]==ans2[i])
        {
            if(ans1[i]>='0'&&ans1[i]<='9')
            {
                printf("%02d:",ans1[i]-'0');break;
            }
            else if(ans1[i]>='A'&&ans1[i]<='N')
            {
                printf("%02d:",ans1[i]-'A'+10); break;
            }
        }
    }
    for(int j=0;j<len3&&j<len4;j++)
    {
        if(ans3[j]==ans4[j]&&((ans3[j]>='A'&&ans3[j]<='Z')||(ans3[j]>='a'&&ans3[j]<='z')) )
        {
                printf("%02d",j);break;
        }
    }
    return 0;
 } 

参考了柳婼解法,人家的解法是这个:

#include <iostream>
#include <cctype>
using namespace std;
int main() {
        string a, b, c, d;
        cin >> a >> b >> c >> d;
        char t[2];
        int pos, i = 0, j = 0;
        while(i < a.length() && i < b.length()) {
                if (a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G')) {
                        t[0] = a[i];
                        break;
                    }
                i++;
                }
         i = i + 1;
         while (i < a.length() && i < b.length()) {
         if (a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i]))) {
                 t[1] = a[i];
                 break;
         }
         i++;
 }
             while (j < c.length() && j < d.length()) {
                     if (c[j] == d[j] && isalpha(c[j])) {
                     pos = j;
                     break;
     }
         j++;
 }
 string week[7] = {"MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
 int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
 cout << week[t[0]-'A'];
 printf("%02d:%02d", m, pos);
 return 0;
}

PAT甲级——1061 Dating (20分)的更多相关文章

  1. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  2. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  3. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  4. PAT甲级——1061 Dating

    1061 Dating Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2 ...

  5. 【PAT甲级】1061 Dating (20 分)

    题意: 给出四组字符串,前两串中第一个位置相同且大小相等的大写字母(A~G)代表了周几,前两串中第二个位置相同且大小相等的大写字母或者数字(0~9,A~N)代表了几点,后两串中第一个位置相同且大小相等 ...

  6. PAT Basic 1014 福尔摩斯的约会 (20 分) Advanced 1061 Dating (20 分)

    大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...

  7. PAT甲级——1035 Password (20分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  8. 1061 Dating (20分)

    Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...

  9. PAT甲级1061 Dating

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805411985604608 题意: 给定四个字符串. 前两个字符串 ...

随机推荐

  1. SQL优化工具 - SQL Server Profiler与数据库引擎优化顾问

    最近项目做到几千个学生分别去人脸识别记录(目前约630000行)中查询最后一次记录,可想而知性能这块是个麻烦.于是乎,GET到了SQL Server Profiler和数据库引擎优化顾问这俩工SHEN ...

  2. java如何连接Oracle数据库问题

    Oracle数据库纯属自学,不对请留言改正! 在学Oracle前相信已经大致知道mysql或sqlserver数据库,这个跟前面两个不大一样,你安装的时候让你输入一个密码,貌似是一个系统管理员密码,跟 ...

  3. 最简单的前端获取后台的json值(后台怎么返回一个json对象到前台)

    (说一下这个外部包jackson一般不用了,现在大家都用马云儿子的FastJson 下面服务器代码我就不改了大家随意用什么外部包)2019.1.14日改 我使用了外部包jackson(杰克逊哈哈哈啊) ...

  4. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:SSM(Spring+Spring MVC+MyBatis)框架整合搭建详细步骤

    因为 Spring MVC 是 Spring 框架中的一个子模块,所以 Spring 与 SpringMVC 之间不存在整合的问题.实际上,SSM 框架的整合只涉及 Spring 与 MyBatis ...

  5. lastz

    lastz sequence1.fasta sequence2.fasta 其中,sequence1.fasta是reference genome :sequence2.fasta是需要比对的geno ...

  6. C语言拾遗——inttypes.h

    今天偶然间看到这个头文件inttypes,好奇有什么用,去找度娘玩了一波,发现这头文件挺有意思的. 这个头文件适配于C99标准,它提供整数输入的各种进制转换的宏,这是在Ubuntu上扣下来的代码(wi ...

  7. 51nod 1435:位数阶乘

    1435 位数阶乘 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 X是一个n位数的正整数 (x=a0a1...a ...

  8. NCRE的JAVA二级考试大纲

    全国计算机等级考试二级 Java 语言 程序设计考试大纲(2018 年版) 基本要求 1. 掌握 Java 语言的特点.实现机制和体系结构. 2. 掌握 Java 语言中面向对象的特性. 3. 掌握 ...

  9. 在java中如何根据手机号查询号码归属地

    1.maven项目中配置 <dependency><groupId>com.googlecode.libphonenumber</groupId><artif ...

  10. java.io.tmpdir在哪里?

    查找所在目录的方式如下: System.out.println(System.getProperty(“java.io.tmpdir”)); System.getProperty(),还可以获取更多其 ...