PAT (Advanced Level) 1061. Dating (20) 字符匹配
2015-07-28 10:28
190 查看
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
/*2015.7.28cyq*/ #include <iostream> #include <string> #include <fstream> #include <vector> using namespace std; //ifstream fin("case1.txt"); //#define cin fin int main(){ string days[8]={"MON","TUE","WED","THU","FRI","SAT","SUN"}; string s1,s2,s3,s4,day; int h,m; cin>>s1>>s2>>s3>>s4; int i; for(i=0;i<s1.size()&&i<s2.size();i++){ if(s1[i]==s2[i]&&s1[i]>='A'&&s1[i]<='G'){ day=days[s1[i]-'A']; break; } } i++; for( ;i<s1.size()&&i<s2.size();i++){ if(s1[i]==s2[i]){ if(s1[i]>='0'&&s1[i]<='9'){ h=s1[i]-'0'; break; } if(s1[i]>='A'&&s1[i]<='N'){ h=s1[i]-'A'+10; break; } } } for(int j=0;j<s3.size()&&j<s4.size();j++){ if(s3[j]==s4[j]){ if((s3[j]>='a'&&s3[j]<='z')||(s3[j]>='A'&&s3[j]<='Z')){ m=j; break; } } } cout<<day; printf(" %02d:%02d",h,m); return 0; }
相关文章推荐
- Poj -2586 Y2K Accounting Bug--枚举
- 机器视觉代码集合
- LeetCode_107 Binary Tree Level Order Traversal II
- 异常处理(Python)
- Spring MVC学习------------转发和重定向
- 帮大家区分易宝支付和支付宝。(转载)
- Different Ways to Add Parentheses
- ios 使用xib时,在UIScrollView中添建内容view时,使用约束的注意
- AsyncTask的介绍及基本使用方法
- java Longest Palindromic Substring(最长回文字符串)
- poj2409--Let it Bead(置换群+polya奇数)
- 【iOS】MD5加密与网络数据安全
- Apache Shiro 使用手册(一)Shiro架构介绍
- 分布数数据库事物
- Linux内核抢占实现机制分析
- java 验证码之 Jcaptcha;springMVC 验证码
- openflow详解
- 为STARUML写的自动生成文档脚本
- EL表达式截取字符串
- 网络请求之GET、POST请求