PAT A 甲级 1061 Dating (20分)

1061 Dating (20分)

吐槽

怎么会有这么从各种意义上都糟糕透顶了的题目的?????

不仅题面又臭又长又难懂
而且条件描写模糊不清或者起码让人不敢确定
甚至题目内容还充满了不得不大量if+switch七个case的情况(虽然后者可以用enum简化但我也不觉得有啥区别)
而其本质却是个毫无难度、没有上面这堆鬼情况一分钟就能写完的比对字符串内字母?

我人傻了。

思路

这道题……本质是个字符比对。
我不特别确定它的题意(指具体是什么样的比对要求),但我按以下理解写是AC了的:

输入四段string,
找到前两个里面第一个在同一个位置出现了的A-G之间的字母(必须大写+必须A-G(因为只有七天)),它在字母表中顺序数代表了周几(A-周一MON,B-周二TUE……)
找到前两个里面第二个在同一个位置出现了的0-9或A-N之间的字符。视其为一个24进制数,它的值代表了小时(0-9→0-9,A-N→10-23)。
找到后两个里面第一个在同一个位置出现了的字母。其在字符串中的位置代表了分钟。
然后输出。

测点

测点0和5是分钟数不到十位要补零。
测点1是“最先找到的第二个相同的字符是a-n”(是不合规的)。
测点2里是“第二个相同的字符不在0-9、A-N的范围内”。
测点4是小时数不到十位要补零。

别问我为啥把所有测点都测了,我自己就错了一次周几的缩写没大写,但女友的python代码把上面0、5以外测点全错了个遍。我debug了老半天发现把其他测点都测到了AC了之后基本也猜出05是啥了所以顺手也测了。

代码(C++)

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s1, s2, s3, s4;
	cin >> s1 >> s2 >> s3 >> s4;
	int i;
	for (i = 0;; i++)
		if (s1[i] == s2[i] && s1[i] >= 'A'&&s1[i] <= 'G')
			break;
	switch (s1[i])
	{
	case 'A':cout << "MON"; break;
	case 'B':cout << "TUE"; break;
	case 'C':cout << "WED"; break;
	case 'D':cout << "THU"; break;
	case 'E':cout << "FRI"; break;
	case 'F':cout << "SAT"; break;
	case 'G':cout << "SUN"; break;
	default:
		break;
	}
	i++;
	cout << " ";
	for (;; i++)
	{
		if (s1[i] == s2[i])
		{
			if (s1[i] >= '0'&&s1[i] <= '9')
				cout << "0" << s1[i];
			else if (s1[i] >= 'A'&&s1[i] <= 'N')
				cout << (s1[i] - 'A' + 10);
			else
				continue;
			break;
		}
	}
	cout << ":";
	for (i = 0;; i++)
	{
		if (s3[i] == s4[i]&&((s3[i]>='A'&&s3[i]<='Z')||(s3[i]>='a'&&s3[i]<='z')))
		{
			if (i < 10)
				cout << "0" << i;
			else
				cout << i;
			break;
		}
	}
	return 0;
}

代码(Python)

a=input()
b=input()
c=input()
d=input()
l=[]
wen=['MON','TUE','WED','THU','FRI','SAT','SUN']
for i in range(len(a)):
    if 'A'<=a[i]<='G' and b[i]==a[i]:
        l.append(ord(a[i])-ord('A'))
        x=i+1
        break
for i in range(x,len(a)):
    if b[i]==a[i]:
        if '0'<=a[i]<='9':
            l.append(int(a[i]))
            break
        elif 'A'<=a[i]<='N':
            l.append(ord(a[i])-ord('A')+10)
            break
for i in range(len(c)):
    if d[i]==c[i] and ('a'<=c[i]<='z' or 'A'<=c[i]<='Z'):
        l.append(i)
        break
print(wen[l[0]]+' ',end='')
if l[1]<10:
    print('0'+str(l[1]),end='')
else:
    print(l[1],end='')
print(':',end='')
if l[2]<10:
    print('0'+str(l[2]))
else:
    print(l[2])

题目

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值