PAT 1061 Dating[简单]
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-23时,使用0-9+A-N表示;
使用后两个字符串的相同位置的小写字母的位置下标来表示分钟数。
//猛一看感觉还是挺简单的。
#include <iostream>
#include <map>
#include<cstdio>
using namespace std; int main() {
map<char,string> week;
string w[]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
for(int i=;i<;i++){
week['A'+i]=w[i];
}
map<char,int> hour;
for(int i=;i<;i++){
if(i<=)
hour[i+'']=i;
else
hour['A'+i-]=i;
}
string s1,s2,s3,s4;
cin>>s1>>s2>>s3>>s4;
int len1=s1.size(),len2=s2.size();
int len3=s3.size(),len4=s4.size();
bool wk=false;
for(int i=;i<len1&&i<len2;i++){
if(!wk){
if(s1[i]>='A'&&s1[i]<='G'&&s1[i]==s2[i]){
cout<<week[s1[i]]<<" ";//现在星期找到了。
wk=true;
}
}else if(s1[i]==s2[i]){
if(isdigit(s1[i])||(s1[i]>='A'&&s1[i]<='N')){
printf("%02d:",hour[s1[i]]);break;//找到了之后就break,不然之后会有相等的。
} }
}
for(int i=;i<len3&&i<len4;i++){
if(s3[i]==s4[i]&&isalpha(s3[i])){
printf("%02d",i);break;
}
}
return ;
}
//注意在小时数找到之后就立马break,而不是还要循环,因为后面还有可能有相等的,应该break掉。
1.注意map的使用,总的来说还是挺简单的~
PAT 1061 Dating[简单]的更多相关文章
- PAT 1061. Dating
题是别人出的,不按她的想法来也没办法,真心想k一顿 #include <cstdio> #include <cstdlib> using namespace std; cons ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- PAT甲级——1061 Dating
1061 Dating Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2 ...
- PAT 1061 - 1064 题解
这四道题来自 13 年 08 月 30 的 PAT 测试. 代码量不大,思路也比较直接.不过第一题的处理逻辑不太清晰,需要好好把握.稍有不慎就掉进坑里了(很多人被这道 20'的题坑了一个多小时心慌意乱 ...
- 1061 Dating (20 分)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh ...
- PAT (Advanced Level) 1061. Dating (20)
简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...
- PAT甲级1061 Dating
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805411985604608 题意: 给定四个字符串. 前两个字符串 ...
- PAT Basic 1014 福尔摩斯的约会 (20 分) Advanced 1061 Dating (20 分)
大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...
- PAT甲级——1061 Dating (20分)
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...
随机推荐
- 从源代码来理解ArrayList和LinkedList差别
从源代码理解ArrayList和LinkedList差别 ArrayList ArrayList默认容量为10,实质是一个数组用于存放元素,size表示ArrayList所包括的元素个数. Array ...
- MFC 小知识总结五
1 移动无标题对话框 响应WM_NCHITTEST 消息 [cpp] view plaincopy LRESULT CTimeJishiDlg::OnNcHitTest(CPoint point) ...
- Python 入门(六)Dict和Set类型
什么是dict 我们已经知道,list 和 tuple 可以用来表示顺序集合,例如,班里同学的名字: ['Adam', 'Lisa', 'Bart'] 或者考试的成绩列表: [95, 85, 59] ...
- linux连接sybase数据库-isql
转自:http://blog.knowsky.com/196438.htm 想要linux连接sybase数据库用命令isql: isql [-U login id] [-P password] [- ...
- apache编译安装完成后的服务启动设置
Apache安装后可通过其安装路径的bin目录下的apachectl脚本控制服务的启动和停止.本例中apache安装在/usr/local/apache-2.2.6,服务控制脚本为: /usr/loc ...
- 说说M451的例程库的说明
Directory Information Document Driver reference manual and reversion history. Library Driv ...
- excel——之锁定表头不可编辑
前言: 设置excel表头不可编辑功能.效果如下: 这就意味着,不可随意更改表头数据,除非你有密码. 过程: 1.先随意右键打开一个单元格,查看其中的“设置单元格属性”,即 2.在选中想要编辑的那些数 ...
- 安装memcacheq
1.下载memcacheq包 下载地址:http://code.google.com/p/memcacheq/downloads/list 解压包:# tar -zxvf memcache ...
- C++异常 调用abort()
以一个计算两个数的调和平均数的函数为例.两个数的调和平均数的定义是:这两个数倒数的平均值的倒数,因此表达式为:1.0 * x * y / (x + y)如果y是x的负值,则上述公式将导致被零除——一种 ...
- (三)微信小程序之发送服务通知(模板消息)
1.后端获取AccessToken返回给微信端 微信小程序端请求后端得到AccessToken 2.后端获取openid返回给微信端 微信小程序端登录请求后端得到openid 3.发送消息 ...