PAT 1061. Dating (20)(按一定规则找俩个字符串中相同的字符)(待修改)

来源:互联网 发布:python中return的用法 编辑:程序博客网 时间:2024/06/08 18:06

#

1061. Dating (20)

时间限制
100 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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

题目大意

  • 1.找出s1,s2相同的字符(A-G内)。
  • 2.完成第一步后继续在s1,s2中找相同的字符(0-9,A-N)。
  • 3.找出s3,s4中相同的字符(大小写字母)。

待修改代码(问题在哪??)

#include<string>#include<iostream>#include<math.h>#include<cstdio>using namespace std;int main(int argc, char *argv[]){    string s1,s2,s3,s4;    cin >> s1 >> s2 >> s3 >> s4;    int len_min = min(s1.length(),s2.length());    bool flag = false;    for (int i = 0; i < len_min; ++i) {        if (!flag&&s1[i] == s2[i]&&s1[i] >= 'A' && s1[i] <= 'G') {                flag = true;                switch(s1[i] - 'A' + 1){                case 1:                    cout << "MON ";                    break;                case 2:                    cout << "TUE ";                    break;                case 3:                    cout << "WED ";                    break;                case 4:                    cout << "THU ";                    break;                case 5:                    cout << "FRI ";                    break;                case 6:                    cout << "STA ";                    break;                case 7:                    cout << "SUN ";                }                continue;            }        if (flag&&s1[i] == s2[i]&&((s1[i] >= 'A' && s1[i] <= 'G')||(s1[i] >= '0' && s1[i] <= '9'))) {            if (s1[i] >= 'A' && s1[i] <= 'N') {                cout << (int)(s1[i]-'A'+10)<<":";            }else if (s1[i]>='0' && s1[i]<='9') {                cout << 0 << s1[i] << ":";            }            break;        }    }    len_min = min(s3.length(),s4.length());    int i ;    for (i = 0; i < len_min; ++i) {        if (s3[i] == s4[i]&&((s3[i] >= 'A' && s3[i] <= 'G')||(s3[i] >= 'a' && s3[i] <= 'z'))) {            break;        }    }    printf("%02d\n",i);    return 0;}
0 0
原创粉丝点击