PAT甲级 1061

PAT甲级 1061

题目 Dating

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.

解析

规则一:字符串1和字符串2中字符相等且该字符在A-G范围内,对应一个星期的7天
规则二:字符串1和字符串2中第二个字符相等且该字符在0-9或者A-N之间对应0 to 23 小时
规则三:字符串1和字符串2中字符相等且该字符在a-z或者A-Z之间,他的序号对应分钟

代码

#include<bits/stdc++.h>

#define INF 1<<29

using namespace std;

void pat1061() {

    string str1, str2, str3, str4;
    cin >> str1 >> str2 >> str3 >> str4;
    string DAY;
    int HH = 0, MM = 0;
    bool flag = false;
    for (int i = 0; i < str1.size() || i < str2.size(); ++i) {
        if (str1[i] == str2[i]) {
            if (!flag) {
                if (str1[i] >= 'A' && str1[i] <= 'G') {
                    int num = str1[i] - 'A' + 1;
                    if (num == 1) {
                        DAY = "MON";
                    } else if (num == 2) {
                        DAY = "TUE";
                    } else if (num == 3) {
                        DAY = "WED";
                    } else if (num == 4) {
                        DAY = "THU";
                    } else if (num == 5) {
                        DAY = "FRI";
                    } else if (num == 6) {
                        DAY = "SAT";
                    } else {
                        DAY = "SUN";
                    }
                    flag = true;
                }
            } else {
                if (str1[i] >= 'A' && str1[i] <= 'N') {
                    HH = str1[i] - 'A' + 10;
                    break;
                } else if (str1[i] >= '0' && str1[i] <= '9') {
                    HH = str1[i] - '0';
                    break;
                }

            }
        }
    }
    for (int i = 0; i < str3.size() || i < str4.size(); ++i) {
        if (str3[i] == str4[i]) {
            if ((str3[i] >= 'a' && str3[i] <= 'z') || (str3[i] >= 'A' && str3[i] <= 'Z')) {
                MM = i;
                break;
            }
        }
    }

    printf("%s %02d:%02d\n", DAY.c_str(), HH, MM);
}

int main() {
    pat1061();
    return 0;
}
### 关于 PAT 甲级 1024 PAT (Programming Ability Test) 是一项编程能力测试,其中甲级考试面向有一定编程基础的学生。对于 PAT 甲级 1024 目,虽然具体目描述未直接给出,但从相似类型的目分析来看,这类目通常涉及较为复杂的算法设计。 #### 数据结构的选择与实现 针对此类问,常用的数据结构包括但不限于二叉树节点定义: ```cpp struct Node { int val; Node* lchild, *rchild; }; ``` 此数据结构用于表示二叉树中的节点[^1]。通过这种方式构建的二叉树能够支持多种遍历操作,如前序、中序和后序遍历等。 #### 算法思路 当处理涉及到图论的问时,深度优先搜索(DFS)是一种常见的解策略。特别是当需要寻找最优路径或访问尽可能多的节点时,结合贪心算法可以在某些情况下提供有效的解决方案[^2]。 #### 输入输出格式说明 根据以往的经验,在解决 PAT 类型的问时,输入部分往往遵循特定模式。例如,给定 N 行输入来描述每个节点的信息,每行按照如下格式:“Address Data Next”,这有助于理解如何解析输入并建立相应的数据模型[^4]。 #### 数学运算示例 有时也会遇到基本算术表达式的求值问,比如分数之间的加减乘除运算。下面是一些简单的例子展示不同情况下的计算结果: - \( \frac{2}{3} + (-2) = -\frac{7}{3}\) -2) = -\frac{4}{3}\) - \( \frac{2}{3} ÷ (-2) = -\frac{1}{3}\) 这些运算是基于样例提供的信息得出的结果[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值