PAT甲级1061 Dating

题目https://pintia.cn/problem-sets/994805342720868352/problems/994805411985604608

题意:

给定四个字符串。

前两个字符串中第一个相同的大写字母对应星期,第二个相同的数字或大写(A~N)表示小时。

后两个字符串中第一个相同的字母对应分钟。

这里的对应都是位置与位置一一对应。

思路:

按照题意简单模拟。要看清楚题目数据的要求。比如分钟要求的是English letter,数字相同是不算的。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<map>
 4 #include<set>
 5 #include<iostream>
 6 #include<cstring>
 7 #include<algorithm>
 8 #include<vector>
 9 #include<cmath> 
10 #include<stack>
11 #include<queue>
12 
13 #define inf 0x7fffffff
14 using namespace std;
15 typedef long long LL;
16 typedef pair<string, string> pr;
17 
18 string code[5];
19 int len[5];
20 string day[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
21 
22 int main()
23 {
24     for(int i = 0; i < 4; i++){
25         cin>>code[i];
26     }
27     
28     char ch[2];
29     int cnt = 0;
30     for(int i = 0; i < min(code[0].length(), code[1].length()); i++){
31         if(code[0][i] == code[1][i]){
32             if(cnt == 0 && code[0][i] >= 'A' && code[0][i] <= 'G')
33                 ch[cnt++] = code[0][i];
34             else if(cnt == 1 && (code[0][i] >= 'A' && code[0][i] <= 'N' || code[0][i] >= '0' && code[0][i] <= '9'))
35                 ch[cnt++] = code[0][i];
36         }
37         if(cnt == 2)break;
38     }
39     
40     //cout<<ch[0]<<ch[1]<<endl;
41     int pos;
42     for(int i = 0; i < min(code[2].length(), code[3].length()); i++){
43         if(code[2][i] == code[3][i] && (code[2][i] >= 'a' && code[2][i] <= 'z' || code[2][i] >= 'A' && code[2][i] <= 'Z')){
44             pos = i;
45             break;
46         }
47     }
48     
49     int h;
50     if(ch[1] >= 'A' && ch[1] <= 'N'){
51         h = ch[1] - 'A' + 10;
52     }
53     else{
54         h = ch[1] - '0';
55     }
56     int d = ch[0] - 'A';
57     cout<<day[d];
58     printf(" %02d:%02d
", h, pos);
59     return 0;
60 }
原文地址:https://www.cnblogs.com/wyboooo/p/10448630.html