PAT basic 1014 福尔摩斯的约会 (20分) C++ 测试点二错误解释

一、题目描述

1014 福尔摩斯的约会 (20分)
大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间星期四 14:04,因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 D,代表星期四;第 2 对相同的字符是 E ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 23 点由数字 0 到 9、以及大写字母 A 到 N 表示);后面两字符串第 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<stdlib.h>
#include<string>
#include<cmath>
#include<iostream>
using namespace std;

int min(int a, int b)
{
	return a > b ? b : a;
}

void check2(string c, string d)
{
	for (int i = 0; i < min(c.length(), d.length()); i++)
	{
		if (c[i] == d[i] && 
			((c[i]>='A'&&c[i]<='Z')||(c[i] >= 'a'&&c[i] <= 'z')))
		{
			if (i < 10)
			{
				cout << "0" << i; break;
			}
			else 
				if (i < 60 )
				{
					cout << i;
					break;
				}
		}
	}
}

void printday(char x)
{
	string day[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
	cout << day[x - 'A'] << " ";
}

void printhour(char x)
{
	if (x >= '0'&&x <= '9')
	{
		cout << "0"<<x << ":";
	}
	else
	{
		cout << 10 + x - 'A' << ":";
	}
}

int main()
{
	string a, b, c, d;
	int count=0;
	cin >> a >> b >> c >> d;
	int lengthmin = a.length() > b.length() ? b.length(): a.length();
	for (int i = 0; i < lengthmin; i++)
	{
				
		if (a[i] == b[i])
		{
			if (a[i] >= 'A'&&a[i] < 'A' + 7 && count==0)
			{
					printday(a[i]);
					count = 1;
			}
			else 
				if ((a[i] >= '0'&&a[i] <= '9' &&count == 1) ||(a[i] >= 'A') && (a[i] <= 'A' + 13 &&count==1))
				{
					printhour(a[i]);
					break;//测试点2,后面可能有多组一致的,所以一定得跳出循环
				}

		}
	}
	check2(c,d);
	system("pause");
	return 0;
}

三、运行结果

在这里插入图片描述

四、题目合集

点这里~

发布了42 篇原创文章 · 获赞 0 · 访问量 776

猜你喜欢

转载自blog.csdn.net/qq_44352065/article/details/103831212