• 【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.

    Sample Input:

    3485djDkxh4hhGE 
    2984akDfkkkkggEdsb 
    s&hgsfdk 
    d&Hyscvnm

    Sample Output:

    THU 14:04

    解题思路:

    题目就是给出4个字符串,让我们找到相同的英文字符,再进行相应的运算,求出时间就可以了。

    用数组来存储星期一到星期日会方便一点。

    易错点:

    1. 第一次相同的字母必须在'A'-'G'之间;

    2. 第二次相同的必须在'A'-'N'或者'0'-'9'之间;

    3. 确定分钟的相同字符一定要是英文字母即'A'-'Z'或者'a'-'z';

    4. 一定要确保你星期一到星期天的英文字母正确!!!!

    代码:

    1. #include
    2. using namespace std;
    3. int main(){
    4. string a,b,c,d;
    5. cin>>a>>b>>c>>d;
    6. char index1 = NULL;
    7. char index2;
    8. string hh;
    9. string ss;
    10. int flag = 0;
    11. string Day[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    12. for(int i=0;isize();i++){
    13. if(a[i]==b[i]&&flag &&(a[i]>='A'&&a[i]<='N'||a[i]>='0'&&a[i]<='9')){
    14. index2 = a[i];
    15. break;
    16. }
    17. if(index1 == NULL && a[i]==b[i] && a[i]>='A'&&a[i]<='G'){
    18. index1 = a[i];
    19. flag = 1;
    20. }
    21. }
    22. if(index2>='0'&&index2<='9'){
    23. hh+=to_string(index2-'0');
    24. }else{
    25. hh+=to_string(10+index2-'A');
    26. }
    27. for(int i=0;isize();i++){
    28. if(c[i]==d[i] && (c[i]>='A'&&c[i]<='Z'||c[i]>='a'&&c[i]<='z')) {
    29. ss = to_string(i);
    30. break;
    31. }
    32. }
    33. if(ss.size()==1) ss = "0"+ss;
    34. if(hh.size()==1) hh = "0"+hh;
    35. cout<'A'+1)%7]<<" "<":"<
    36. return 0;
    37. }

  • 相关阅读:
    网络安全(黑客)——自学2024
    如何使用VMware12PRO安装Mac OS
    Doris 2.0.1 DockerFile版 升级实战
    重大技术问题,iPhone 15 Pro Max面临“烧屏门”风波 | 百能云芯
    排序的学习(一)
    笨方法学Python
    虚拟机搭载Linux · VMware + Ubuntu 部署 路线参考(20.04.5)
    2023秋招—大数据开发面经—卓望数码
    大模型日报2024-04-23
    MySQL之完整性约束
  • 原文地址:https://blog.csdn.net/weixin_55202895/article/details/126726272