PAT甲级 1061 Dating

原题链接:

https://pintia.cn/problem-sets/994805342720868352/exam/problems/type/7?problemSetProblemId=994805411985604608&page=0

注意点:

1.题意理解:

  • 这个题是将一对字符串中相同位置的字符进行比较。
  • DAY HH:MM不同位置要求的相同字符不同,DAY为‘A'-'G',HH为’0‘-’9‘和‘A'-'N',MM的位置是从0开始的。

代码:

#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define endl '\n'

string str1, str2, str3, str4;

string week[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> str1 >> str2 >> str3 >> str4;
	char c1;
	int i2=0,i3=0;
	bool flag = false;//代表是否找到c1
	int len1 = min(str1.size(), str2.size());
	for (int i = 0; i < len1; i++) {
		if (str1[i] == str2[i]) {
			if (!flag) {
				if (str1[i] >= 'A' && str1[i] <= 'G') {
					c1 = str1[i];
					flag = true;
				}
			}
			else{
				if (str1[i] >= 'A' && str1[i] <= 'N'||str1[i]>='0'&&str1[i]<='9') {
					if (str1[i] >= '0' && str1[i] <= '9') {
						i2 = str1[i] - '0';
					}
					else {
						i2 = str1[i] - 'A' + 10;
					}
					break;
				}
			}
		}
	}
	int len2 = min(str3.size(), str4.size());
	for (int i = 0; i < len2; i++) {
		if (str3[i] == str4[i]&&str3[i]>='a'&&str3[i]<='z'|| str3[i] >= 'A' && str3[i] <= 'Z') {
			i3 = i;
			break;
		}
	}

	cout << week[c1 - 'A'] << " ";
	cout << setw(2) << setfill('0') << i2;
	cout << ':';
	cout << setw(2) << setfill('0') << i3;


	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值