PAT-1014 福尔摩斯的约会

版权声明:一只努力变强的编程汪,欢迎交流! https://blog.csdn.net/qq_42020563/article/details/83930719

1014 福尔摩斯的约会 (20 分)

大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间星期四 14:04,因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,代表星期四;第 2 对相同的字符是 E ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 23 点由数字 0 到 9、以及大写字母 AN 表示);后面两字符串第 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
#include<iostream>
#include<string>
using namespace std;
void Week(int d)
{
  if(d==1)
  {
    cout<<"MON ";
  }
  else if(d==2)
  {
    cout<<"TUE ";
  }
  else if(d==3)
  { 
    cout<<"WED ";
  }
  else if(d==4)
  {
    cout<<"THU ";
  }
  else if(d==5)
  {
    cout<<"FRI ";
  }
  else if(d==6)
  {
    cout<<"SAT ";
  }
  else if(d==7)
  {
    cout<<"SUN ";
  }
}
int main()
{
	string s1,s2,s3,s4;
	cin>>s1>>s2>>s3>>s4;
	int l1=s1.length();
  int l2=s2.length();
  int l3=s3.length();
  int l4=s4.length();
  int min1,min2;
  if(l1>l2)
  {
    min1=l2;
  }
  else
  {
    min1=l1;
  }
  if(l3>l4)
  {
    min2=l4;
  }
  else
  {
    min2=l3;
  }
  int n=0,h,m;
	for(int i=0;i<min1;i++)
	{
		if(s1[i]==s2[i])
		{
		  if(n==0)
			{
		  if(s1[i]>='A'&&s1[i]<='G')
			{
				n=s1[i]-'A'+1;
				Week(n);
			}		
			}
		  else 
			{
				if(s1[i]>='0'&&s1[i]<='9')
				{	
				  h=s1[i]-'0';
					cout<<"0"<<h<<":";
					break;
				}
				else if(s1[i]>='A'&&s1[i]<='N')
				{
					h=s1[i]-'A'+10;
					cout<<h<<":";
					break;
				}
			}
		
		}
	}
	for(int i=0;i<min2;i++)
	{
		if(s3[i]==s4[i]&&(s3[i]>='A'&&s3[i]<='Z'||s3[i]>='a'&&s3[i]<='z'))
		{
			if(i<10)
			cout<<"0";
			cout<<i;
			break;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42020563/article/details/83930719
今日推荐