PAT BASIC LEVEL 1014. 福尔摩斯的约会 (20)
来源:互联网 发布:js 判断对象是否包含 编辑:程序博客网 时间:2024/05/16 14:41
1014. 福尔摩斯的约会 (20)
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母’D’,代表星期四;第2对相同的字符是’E’,那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母’s’出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
输入格式:
输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。
输出格式:
在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
输入样例:3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm输出样例:
THU 14:04
Answer:
#include<iostream>using namespace std;bool is_upper(char c, char end) { return c >= 'A' && c <= end;}bool is_lower(char c) { return c >= 'a' && c <= 'z';}bool is_alpha(char c) { return is_upper(c, 'Z') || is_lower(c);}bool is_digit(char c) { return c >= '0' && c <= '9';}int get_day(char* str1, char* str2, int* index) { while(str1[*index] && str2[*index]) { if(str1[*index] == str2[*index]) if(is_upper(str1[*index], 'G')) return str1[*index] - 'A'; (*index) ++; }}int get_hour(char* str1, char* str2, int* index) { while(str1[*index] && str2[*index]) { if(str1[*index] == str2[*index]) { if(is_upper(str1[*index], 'N')) { return str1[*index] - 'A' + 10; } else if(is_digit(str1[*index])) { return str1[*index] - '0'; } } (*index) ++; }}int get_minute(char* str3, char* str4) { int index = 0; while(str3[index] && str4[index]) { if(str3[index] == str4[index] && is_alpha(str3[index])) return index; index ++; }}int main() { char input[4][61]; for(int i = 0; i < 4; i ++) { cin >> input[i]; } int index = 0; int day = get_day(input[0], input[1], &index); index ++; int hour = get_hour(input[0], input[1], &index); int minute = get_minute(input[2], input[3]); switch(day) { case 0:cout << "MON ";break; case 1:cout << "TUE ";break; case 2:cout << "WED ";break; case 3:cout << "THU ";break; case 4:cout << "FRI ";break; case 5:cout << "SAT ";break; case 6:cout << "SUN ";break; } cout << hour/10 << hour%10 << ':' << minute/10 << minute%10;}
PS.
最后把判断大写字母的函数is_upper()
加上末位限制于是通过,不知为何有点恼火。
因此把获取day
、hour
、minute
的代码抽取成了函数。
(我是笨蛋吧。)
0 0
- 【C++】浙大PAT (Basic Level)1014. 福尔摩斯的约会 (20)
- PAT Basic Level 1014. 福尔摩斯的约会(20)
- PAT (Basic Level) Practise 1014. 福尔摩斯的约会 (20)
- PAT BASIC LEVEL 1014. 福尔摩斯的约会 (20)
- Basic Level 1014. 福尔摩斯的约会 (20)
- 【PAT 乙级(Basic Level)】福尔摩斯的约会
- PAT(Basic Level)_1014_福尔摩斯的约会
- PAT (Basic Level) Practise (中文)1014.福尔摩斯的约会
- PAT.Basic Level. T.1014.福尔摩斯的约会
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文) 1014. 福尔摩斯的约会 (20)
- PAT (Basic Level) Practise (中文)1014. 福尔摩斯的约会 (20)
- Pat(Basic Level)Practice--1014(福尔摩斯的约会)
- PAT乙级(Basic Level)真题 >福尔摩斯的约会
- PAT乙级(Basic Level)真题1004福尔摩斯的约会 (20)
- PAT basic 1014 : 福尔摩斯的约会
- PAT BASIC 1014 福尔摩斯的约会
- PAT 1014. 福尔摩斯的约会 (20)
- 关于sql server安装出现注册表不一致
- 消息队列使用的四种场景介绍
- Java的动态代理机制及Spring的实现方式
- ReentrantLock锁
- Hybird app阶段分析
- PAT BASIC LEVEL 1014. 福尔摩斯的约会 (20)
- VMWare+ubuntu 使用记录
- 大米云主机首批优秀体验师新鲜出炉——综合篇
- 免费邮箱:收发服务器动态公网地址
- 设计模式:外观模式-facade
- 二、模块详解2
- webpack-dev-server使用方法
- tomcat线程数
- 简单的基于LruCache的图片加载器