1061. Dating (20)
2016-02-15 15:42
393 查看
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:
Sample Output:
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 <iostream> #include <algorithm> #include <string> #include <algorithm> using namespace std; inline bool is_capital_or_digital(char s){return (s >= 'A' && s <= 'N') || (s >= '0' && s <= '9');} inline bool is_capital(char s) { return (s >= 'A' && s <= 'G'); } inline bool is_letter(char s) { return (s >= 'a' && s <= 'z')||(s>='A' && s<='Z'); } int char2int(char s) { if (s >= '0' && s <= '9')return s - '0'; if (s >= 'A' && s <= 'N')return s - 'A'+10; } char * weeks[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" }; int main() { string s1, s2, s3, s4; cin >> s1 >> s2 >> s3 >> s4; char day, h; int m; int i; for (i = 0; i < s1.size() && i < s2.size(); i++) { if (is_capital(s1[i]) && is_capital(s2[i]) && s1[i] == s2[i]) { day = s1[i++]; break; } } for (; i < s1.size() && i < s2.size(); i++) { if (is_capital_or_digital(s1[i]) && is_capital_or_digital(s2[i]) && s1[i] == s2[i]) { h = s1[i]; break; } } for (i=0; i < s3.size() && i < s4.size(); i++) { if (is_letter(s3[i]) && is_letter(s4[i]) && s3[i] == s4[i]) { m = i; break; } } printf("%s %02d:%02d\n", weeks[day - 'A'], char2int(h), m); return 0; }
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)
- 1006. 换个格式输出整数(PAT Basic)
- 1007. 素数对猜想(PAT Basic)
- 1008. 数组元素循环右移问题
- 1009. 说反话(PAT Basic)
- 1011. A+B和C(PAT Basic)