B1014. 福尔摩斯的约会
14/20
#include<bits/stdc++.h>
using namespace std;
map<char,string> day;
int main(){
day['A']="MON";
day['B']="TUE";
day['C']="WED";
day['D']="THU";
day['E']="FRI";
day['F']="SAT";
day['G']="SUN";
string a,b,c,d;
char date;
char hour;
bool flag[2]={false};
cin>>a>>b>>c>>d;
int index=0,len=min(a.length(),b.length());
for(int i=0;i<len;i++){
if(flag[0]&&flag[1])break;//both found.
//find 0~9 A~N
if(flag[0]&&a[i]==b[i]&&((a[i]>=0&&a[i]<=9)||(a[i]>='A'&&a[i]<='N'))&&!flag[1]){hour=a[i];flag[1]=true;}
//find A~G
if(a[i]==b[i]&&a[i]>='A'&&a[i]<='G'&&!flag[0]){date=a[i];flag[0]=true;}
}
cout<<day[date]<<' ';
if(hour>=0&&hour<=9)cout<<hour<<':';
else cout<<10+hour-'A'<<':';
int len2=min(c.length(),d.length());
int index2=0;
for(int i=0;i<len2;i++){
if(c[i]==d[i]&&((c[i]>='a'&&c[i]<='z')||(c[i]<='Z'&&c[i]>='A'))){index2=i;break;}
}
printf("%02d\n",index2);
return 0;
}
排查bug真是心酸。原来没有格式化,我下面的分钟都格式化了,却没有给小时格式化,太傻了。
20/20
#include<bits/stdc++.h>
using namespace std;
map<char,string> day;
int main(){
day['A']="MON";
day['B']="TUE";
day['C']="WED";
day['D']="THU";
day['E']="FRI";
day['F']="SAT";
day['G']="SUN";
string a,b,c,d;
char date;
char hour;
bool flag[2]={false};
cin>>a>>b>>c>>d;
int len=min(a.length(),b.length());
for(int i=0;i<len;i++){
if(flag[0]&&flag[1])break;//both found.
//find 0~9 A~N
if(flag[0]&&a[i]==b[i]&&((a[i]>='0'&&a[i]<='9')||(a[i]>='A'&&a[i]<='N'))&&!flag[1]){hour=a[i];flag[1]=true;}
//find A~G
if(a[i]==b[i]&&a[i]>='A'&&a[i]<='G'&&!flag[0]){date=a[i];flag[0]=true;}
}
cout<<day[date]<<' ';
if(hour>='0'&&hour<='9')printf("%02d:",hour-'0');
else printf("%02d:",hour-'A'+10);
int len2=min(c.length(),d.length());
int index2=0;
for(int i=0;i<len2;i++){
if(c[i]==d[i]&&((c[i]>='a'&&c[i]<='z')||(c[i]<='Z'&&c[i]>='A'))){index2=i;break;}
}
printf("%02d\n",index2);
return 0;
}
B1014. 福尔摩斯的约会的更多相关文章
- 【算法笔记】B1014 福尔摩斯的约会
1014 福尔摩斯的约会 (20 分) 大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hy ...
- 【PAT】B1014 福尔摩斯的约会
因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母D,代表星期四: 第 2 对相同的字符是 E ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 ...
- PAT乙级 1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大侦探福尔摩斯接到一张奇怪的 ...
- PAT-乙级-1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大侦探福尔摩斯接到一张奇怪的 ...
- 浙江大学PAT上机题解析之1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT 乙级 1014 福尔摩斯的约会 (20) C++版
1014. 福尔摩斯的约会 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 大侦探福尔摩斯接到一张奇怪的 ...
- PAT 1014 福尔摩斯的约会 (20)(代码+思路)
1014 福尔摩斯的约会 (20)(20 分) 大侦探福尔摩斯接到一张奇怪的字条:"我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfd ...
- 【PAT】1014. 福尔摩斯的约会 (20)
1014. 福尔摩斯的约会 (20) 大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hy ...
- PAT (Basic Level) Practise (中文)- 1014. 福尔摩斯的约会 (20)
http://www.patest.cn/contests/pat-b-practise/1014 1014. 福尔摩斯的约会 (20) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 ...
随机推荐
- PyQt5--ToolBar
# -*- coding:utf-8 -*- ''' Created on Sep 14, 2018 @author: SaShuangYiBing ''' import sys from PyQt5 ...
- Spring IOC容器创建bean过程浅析
1. 背景 Spring框架本身非常庞大,源码阅读可以从Spring IOC容器的实现开始一点点了解.然而即便是IOC容器,代码仍然是非常多,短时间内全部精读完并不现实 本文分析比较浅,而完整的IOC ...
- sed 指定行范围匹配(转)
sed -n '5,10{/pattern/p}' file sed是一个非交互性性文本编辑器,它编辑文件或标准输入 导出的文件拷贝.标准输入可能是来自键盘.文件重定向.字符串或变量,或者是一个管道文 ...
- 10.Solr4.10.3数据导入(DIH全量增量同步Mysql数据)
转载请出自出处:http://www.cnblogs.com/hd3013779515/ 1.创建MySQL数据 create database solr; use solr; DROP TABLE ...
- 【转】网段,子网掩码,网络标识,IP划分
网段指一个计算机网络中使用同一物理层设备(传输介质,中继器,集线器等)直接通讯的那一部分.就是从一个IP到另一个IP 好比 从192.168.0.1到192.168.255.255这之间就是一个网段 ...
- kubernetes备份和恢复
kubernetes备份和恢复 备份etcd数据 首先由于ETCD有三个备份,并且会同步,所以您只需要在一台master机器上执行ETCD备份即可. 另外在运行下列命令前,确保当前机器的kube- ...
- ubuntu16.04之sudo问题
问题描述: 我通过useradd test创建了test用户,并通过mkdir test创建了该用户对应的目录,再通过chown -R test /home/test将该目录及其子目录权限授予给tes ...
- oracle偏爱hostname
记住: 只要是在使用oracle他家的产品,比如oracle database , weblogic :或者诸如此类,等等,等等,随便别的什么东西 首先要查改: /etc/hosts 127.0.0. ...
- CentOS7+ anaconda3 + Python-3.6 + tensorflow-cpu-1.5安装和配置
CentOS7+ anaconda3 + Python-3.6 + tensorflow-cpu-1.5安装和配置 ========================================== ...
- maven使用及创建项目
一:简单介绍 他是一个帮我们管理jar,并帮助我们处理jar包依赖. 他是一个我们编译.测试.运行.打包的一键构建. 我们在使用后面的命令的同时,前面的过程也自动执行. 二.仓库的分类: 分本地仓库. ...