PAT 1061. Dating

题是别人出的,不按她的想法来也没办法,真心想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[64] = {0};
    char b[64] = {0};
    char c[64] = {0};
    char d[64] = {0};
    
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    scanf("%s", d);
    
    int i = 0, j= 0;
    char day = -1;
    char hour= 0;
    char min = 0;
    char ta, tb;
    while ((ta = a[i++]) != '\0' && (tb = b[j++]) != '\0') {
        if (ta != tb) {
            continue;
        }
        if (is_cap_alpha(ta)) {
            if (day == -1) {
                // range check
                if (ta <= 'G') {
                    day = ta - 'A';
                }
            } else if (ta <= 'N'){
                hour = ta - 'A' + 10;
                break;
            }
        } else if (day != -1 && ta >= '0' && ta <= '9'){
            hour = ta - '0';
            break;
        }
    }
    i = 0, j = 0;
    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 0;
}

 

posted @ 2014-11-23 22:32  卖程序的小歪  阅读(190)  评论(0编辑  收藏  举报