PAT 1061. Dating

时间:2021-02-28 08:55:31

题是别人出的,不按她的想法来也没办法,真心想k一顿

#include <cstdio>
#include <cstdlib> using namespace std; const char* days[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; inline bool is_cap_alpha(char ch) {
return ch >= 'A' && ch <= 'Z';
} inline bool is_alpha(char ch) {
return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z';
} int main() {
char a[] = {};
char b[] = {};
char c[] = {};
char d[] = {}; scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
scanf("%s", d); int i = , j= ;
char day = -;
char hour= ;
char min = ;
char ta, tb;
while ((ta = a[i++]) != '\0' && (tb = b[j++]) != '\0') {
if (ta != tb) {
continue;
}
if (is_cap_alpha(ta)) {
if (day == -) {
// range check
if (ta <= 'G') {
day = ta - 'A';
}
} else if (ta <= 'N'){
hour = ta - 'A' + ;
break;
}
} else if (day != - && ta >= '' && ta <= ''){
hour = ta - '';
break;
}
}
i = , j = ;
while ((ta = c[i]) != '\0' && (tb = d[j]) != '\0') {
if (ta == tb && is_alpha(ta)) {
min = i;
break;
}
i++, j++;
}
printf("%s %02d:%02d\n", days[day], hour, min); return ;
}