【PAT甲级真题】- Dating(20)

题目来源

Dating - 牛客
Dating - PTA

Description

herlock 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 4 4 4th day in a week; the second common character is the 5th capital letter E, representing the 14 14 14th hour (hence the hours from 0 0 0 to 23 23 23 in a day are represented by the numbers from 0 0 0 to 9 9 9 and the capital letters from A A A to N N N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4 4 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 4 4 non-empty strings of no more than 60 60 60 characters without white space in 4 4 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 3 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

题目大意

给出 4 4 4 个字符串密码,按照要求解码

  1. 星期几由前两个字符串的第一个位置相同字母相同的大写字母决定,这个字母是字母表的第几个字母决定是星期几
  2. 小时由前两个字符串的第二个位置相同字符相同的数字或者大写字母 决定, 0 , 9 0,9 0,9 表示 0 0 0 点到 9 9 9 点, A , N A,N A,N 表示 10 10 10 点到 23 23 23 点
  3. 分钟由后两个字符串第一个相同的英文字母的位置 决定,位置为 i i i 即为第 i i i 分钟

思路简介

读懂题目就直接模拟即可

遇到的问题

  1. 判断星期时,可能会出现相同字母大于 G 的情况,即大于第 7 7 7 个字母,要忽略

这点PTA是有测试数据的,但是牛客上没有

代码

cpp 复制代码
/**
 * Dating
 * https://www.nowcoder.com/pat/5/problem/4028
 * https://pintia.cn/problem-sets/994805342720868352/exam/problems/type/7?problemSetProblemId=994805411985604608
 * 模拟
 */
#include<bits/stdc++.h>
using namespace std;

string res1[]={"MON ","TUE ","WED ","THU ","FRI ","SAT ","SUN "};

void solve(){
    string s1,s2,s3,s4;
    cin>>s1>>s2>>s3>>s4;
    int k1=0;
    while(s1[k1]!=s2[k1]||!(s1[k1]>='A'&&s1[k1]<='G'))k1++;
    cout<<res1[s1[k1++]-'A'];//星期
    
    while(s1[k1]!=s2[k1]||!((s1[k1]>='0'&&s1[k1]<='9')||(s1[k1]>='A'&&s1[k1]<='N')))k1++;
    //cout<<s1[k1]<<'\n';
    cout<<setfill('0')<<setw(2)<<(s1[k1]>='0'&&s1[k1]<='9'?s1[k1]-'0':s1[k1]-'A'+10);//24进制时间
    
    k1=0;
    while(s3[k1]!=s4[k1]||!((s3[k1]>='a'&&s3[k1]<='z')||(s3[k1]>='A'&&s3[k1]<='Z')))k1++;
    cout<<':'<<setfill('0')<<setw(2)<<k1<<'\n';//分钟
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //fstream in("in.txt",ios::in);cin.rdbuf(in.rdbuf());
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
相关推荐
布莱克6052 小时前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
沫璃染墨6 小时前
从零入门计算机网络系列(十二):HTTP长连接与会话管理详解——从Connection到Cookie与Session
linux·服务器·c++·tcp/ip·ubuntu·http·交互
xiaoye-duck7 小时前
《C++ 项目:手写大模型接入 SDK》DeepSeek接口设计(下):流式响应实现和测试
开发语言·网络·c++·语言模型
旖旎夜光9 小时前
【C++ 基础入门】类和对象(上):封装、对象模型与 this 指针
开发语言·c++·笔记·学习
小超人诞生日记9 小时前
C++ 智能指针的使用及其原理详解
c++·算法
akinggw10 小时前
libagentcore - 一个基于c++的AI多agent系统升级到2.0版本
开发语言·jvm·c++
繁星蓝雨11 小时前
C++设计原理———多重继承(虚基类、菱形继承、委托、重命名、基类和成员初始化)
c++·委托·多重继承·mi·显式初始化列·虚基类·对象布局
旖旎夜光12 小时前
【C++ 基础入门】命名空间、输入输出、缺省参数与函数重载
开发语言·c++·笔记·学习
扶尔魔ocy13 小时前
【QT入门到晋级】用开源的自定义控件开发
c++·qt·自定义控件
akinggw14 小时前
libsherpacore - 基于 sherpa-onnx 的 C++ 语音交互静态库
c++·交互·语音识别