一开始题目理解错了,以为判断星期和小时的字母可以错开来,没想到下标也必须一样
#include<iostream>
using namespace std;
int result[3];
string week[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
int main() {
string a[2],b[2];
cin >> a[0] >> a[1] >> b[0] >> b[1];
int i;
for (i = 0; i < a[0].size(); i++) {
if (a[0][i] < 'A' || a[0][i]>'G') continue;
if (a[0][i] == a[1][i]) {
result[0] = a[0][i] - 'A';
break;
}
}
for (int k = i+1; k <a[0].size(); k++) {
if (!isdigit(a[0][k]) && a[0][k] < 'A' || a[0][k]>'N')
continue;
if (a[0][k] == a[1][k]) {
result[1] = (a[0][k] < 'A') ? a[0][k] - '0' : a[0][k] - 'A' + 10;
break;
}
}
for (int i = 0; i < b[0].size(); i++) {
if (!isalpha(b[0][i]))
continue;
if (b[0][i] == b[1][i]) {
result[2] = i;
break;
}
}
cout << week[result[0]] << " ";
printf("%02d:%02d", result[1], result[2]);
return 0;
}
|