您的位置:首页 > 其它

PAT(甲级)1061

2015-09-26 11:00 393 查看


1061. Dating (20)

时间限制

50 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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


#include <iostream>
#include <iomanip>
using namespace std;

//////////////////////////////////
// buggggggggggggg!!!
int main()
{
string str1,str2,str3,str4;
cin >>str1 >>str2 >>str3 >>str4;
const char *p1 = &str1[0];
const char *p2 = &str2[0];
int day,hour,min;
bool found=false;
day =-1;
while(*p1 != '\0' && *p2 != '\0'){
if(*p1 == *p2 && *p1 <='G' && *p1 >='A' && !found){
day = *p1-'A'+1;
}
if(*p1 == *p2  && found){
if(*p1 >='0' && *p1 <='9'){
hour = *p1 -'0';
break;
}
else if(*p1 >='A' && *p1 <='N'){
hour = *p1- 'A' + 10;
break;
}
}
if(day != -1)
found = true;
p1++;
p2++;
}
p1 = &str3[0];
p2 = &str4[0];
min = 0;
while(*p1 != '\0' && *p2 !='\0'){
if(*p1 == *p2 && (*p1 <='z' && *p1 >='a' || *p1 >='A' && *p1 <='Z'))
break;
min++;
p1++;
p2++;
}

switch(day){
case 1:{
cout <<"MON " ;
break;
}
case 2:{
cout <<"TUE ";
break;
}
case 3:{
cout <<"WED ";
break;
}
case 4:{
cout <<"THU ";
break;
}
case 5:{
cout <<"FRI ";
break;
}
case 6:{
cout <<"SAT ";
break;
}
case 7:{
cout <<"SUN ";
break;
}
}
cout <<hour <<':' <<setw(2) <<setfill('0') <<min <<endl;//bugggggggggggggggggggggggg!
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: