踩坑点:
代码不严谨所致,详见注释
第1 对相同的大写英文字母代表星期几,范围为A~G,而我却笼统地使用isupper判断,严谨的做法为str1[i] >= ‘A’ && str1[i] <=‘G’
第 2 对相同的字符代表小时,范围为0~9,A~N,笼统地使用isdigit(str1[i]) || isupper(str1[i])判断,严谨的做法为isdigit(str1[i]) || str1[i] >= ‘A’ && str1[i] <=‘N’
// 正确代码:
#include<iostream>
#include<cctype>
using namespace std;
int main() {
string str1, str2, str3, str4, res = "";
int flag = 0, pos;
cin >> str1 >> str2 >> str3 >> str4;
for(int i = 0; i < str1.length() && i < str2.length(); i++) {
if(str1[i] == str2[i]){
if(flag == 1 && (isdigit(str1[i]) || str1[i] >= 'A' && str1[i] <='N')) {
//错误代码:if(flag == 1 && (isdigit(str1[i]) || isupper(str1[i]))) {
res += str1[i];
break;
} else if(str1[i] >='A' && str1[i] <= 'G') {
//错误代码:} else if(isupper(str1[i])) {
res += str1[i];
flag = 1;
}
}
}
for(int i = 0; i < str3.length() && i < str4.length(); i++) {
if(str3[i] == str4[i] && isalpha(str3[i])) {
pos = i; break;
}
}
string day[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
int m = isdigit(res[1]) ? res[1] - '0' : res[1] - 'A' + 10;
cout << day[res[0]-'A'] << " ";
printf("%02d:%02d", m, pos);
return 0;
}