1061. Dating (20)
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&HyscvnmSample Output:
THU 14:04
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//ifstream cin("a.txt");
string str[4];
string s;
int i,j;
char temp;
string day[8] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
bool f1=false,f2=false;
char ff1,ff2;
for( i=0;i<4;i++)
{
cin>>str[i];
}
for(i=0;i<str[1].length()&&i<str[0].length();i++)
{
temp=str[1][i];
if(str[0][i]==temp)
{
if(!f1&&temp<='G'&&temp>='A')
{
f1=true;
ff1=temp;
}
else if(f1&&!f2&&((temp>='A'&&temp<='N')||isdigit(temp)))
{
f2=true;
ff2=temp;
}
else if(f1&&f2)
break;
}
}
int date;
date = ff1 -'A';
cout<<day[date]<<" ";
if(ff2>'9')
cout<<ff2-'A'+10<<":";
else
cout<<"0"<<ff2-'0'<<":";
int pos=-1;
for(i=0;i<str[2].length()&&i<str[3].length();i++)
{
temp=str[2][i];
if(temp==str[3][i]&& isalpha(temp))
{
pos=i;
break;
}
}
if(pos == -1) printf("00\n");
else
printf("%02d\n",pos);
return 0;
}
本文深入探讨了在特定时间限制、内存限制及代码长度限制下的编程技巧,通过具体实例展示了如何高效解决编码问题。重点分析了案例Dating(20),介绍了如何利用字符匹配来解码日期时间,并提供了详细的输入输出规范和代码解析。旨在为开发者提供实用的编程策略和优化思路。
1409

被折叠的 条评论
为什么被折叠?



