原题链接:
注意点:
1.题意理解:
- 这个题是将一对字符串中相同位置的字符进行比较。
- DAY HH:MM不同位置要求的相同字符不同,DAY为‘A'-'G',HH为’0‘-’9‘和‘A'-'N',MM的位置是从0开始的。
代码:
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;
#define endl '\n'
string str1, str2, str3, str4;
string week[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> str1 >> str2 >> str3 >> str4;
char c1;
int i2=0,i3=0;
bool flag = false;//代表是否找到c1
int len1 = min(str1.size(), str2.size());
for (int i = 0; i < len1; i++) {
if (str1[i] == str2[i]) {
if (!flag) {
if (str1[i] >= 'A' && str1[i] <= 'G') {
c1 = str1[i];
flag = true;
}
}
else{
if (str1[i] >= 'A' && str1[i] <= 'N'||str1[i]>='0'&&str1[i]<='9') {
if (str1[i] >= '0' && str1[i] <= '9') {
i2 = str1[i] - '0';
}
else {
i2 = str1[i] - 'A' + 10;
}
break;
}
}
}
}
int len2 = min(str3.size(), str4.size());
for (int i = 0; i < len2; i++) {
if (str3[i] == str4[i]&&str3[i]>='a'&&str3[i]<='z'|| str3[i] >= 'A' && str3[i] <= 'Z') {
i3 = i;
break;
}
}
cout << week[c1 - 'A'] << " ";
cout << setw(2) << setfill('0') << i2;
cout << ':';
cout << setw(2) << setfill('0') << i3;
return 0;
}