Pat(A) 1061. Dating (20)

原题目:

原题链接:https://www.patest.cn/contests/pat-a-practise/1061

1061. Dating (20)


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

题目大意

根据字符串解码出时间,前两个字符串,第一个相同的大写字母是日期,如“D”在字母表中是第4个,故为周四,第二个相同的大写字母或数字是小时,若是0-9便为00-09,若是A-N便是10-23。
后两个字符串,第一次相同的字母位置作为分钟数。

解题报告

题目不难,但有坑点。
需要注意的是:
1. 明白解码方案
1. 表示日期的只能为A-G。
1. 表示小时的是0-9或A-N。
1. 对于小时和分钟,必须格式化输出,即用两位表示。

解决方案就是先读入数据,计算每种月饼的单价,根据单价排序,然后依次遍历月饼,计算收益。

代码

/*
* Problem: 1061. Dating (20)
* Author: HQ
* Time: 2018-03-06
* State: Done
* Memo: 
*/
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;

string fir, sec, thr, fou;

string s2day(char x) {
    string weekdays[] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
    return weekdays[x - 'A'];
}
int main() {
    cin >> fir >> sec >> thr >> fou;
    string day;
    int hour, minite;
    int lf = min(fir.length(),sec.length());
    bool is_day = true;
    for (int i = 0; i < lf; i++) {
        if (fir[i] == sec[i]) {
            if (is_day) {
                if (fir[i] >= 'A' && fir[i] <= 'G') {
                    day = s2day(fir[i]);
                    is_day = false;
                }
            }
            else {
                if (fir[i] >= 'A' && fir[i] <= 'N') {
                    hour = fir[i] - 'A' + 10;
                    break;
                }
                if (isdigit(fir[i])) {
                    hour = fir[i] - '0';
                    break;
                }
            }
        }
    }
    lf = min(thr.length(),fou.length());
    for (int i = 0; i < lf; i++) {
        if (isalpha(thr[i])) {
            if (thr[i] == fou[i]) {
                minite = i;
                break;
            }
        }
    }
    cout << day << " ";
    printf("%02d:%02d\n", hour, minite);
    system("pause");
    //return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值