本题是对字符串的匹配,然后感觉有些繁琐,所以直接找的代码跟着打了一遍,感觉别人的思路很清晰,一步一步的,值得学习
#include<iostream>
#include<string>
using namespace std;
int main() {
string a, b, c, d;
int flag = 0;
string week[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
cin >> a >> b >> c >> d;
int len1 = a.length() > b.length() ? b.length() : a.length();
//寻找第一个相同的大写字母,因为对应的是星期几,所以只找前七个即可
for (int i = 0; i < len1; i++) {
if (a[i] == b[i] && (a[i] >= 65 && a[i] <= 71) && flag == 0) {
flag = 1;
cout << week[a[i] - 65] << " ";
i++;
}
//从第一对相同大写字母后找第二对相同的字符(在0-9和A-N之间)
if (flag == 1 && a[i] == b[i]) {
if (a[i] >= '0'&&a[i] <= '9') {
cout << "0" << a[i] - '0' << ":";
break;
}
if (a[i] >= 'A'&&a[i] <= 'N') {
cout << a[i] - 65 + 10 << ":";
break;
}
}
}
int len2 = c.length() > d.length() ? d.length() : c.length();
//后两个字符串必须满足是两个英文字母相等
for (int i = 0; i < len2; i++) {
if (c[i] == d[i] && ((c[i] >= 65 && c[i] <= 90) || (c[i] >= 97 && c[i] <= 122))) {
if (i <= 9) {//不足两位数补0
cout << "0" << i << endl;
break;
}
else {
cout << i << endl;
break;
}
}
}
return 0;
}