【PAT甲级】1061. Dating (20)

注:date[7][4]第二维应该是4而不是3.

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    char a[61], b[61], c[61], d[61];
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    scanf("%s", d);
    int m = (strlen(a) < strlen(b) ? strlen(a) : strlen(b));
    int n = (strlen(c) < strlen(d) ? strlen(c) : strlen(d));
    char date[7][4] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    int i;
    int da, ho, mi;
    for (i = 0; i < m; i++) {
        if (a[i] == b[i] && a[i] >= 'A' && a[i] <= 'G') {
            da = a[i] - 'A';
            break;
        }
    }
    for (i = i + 1; i < m; i++) {
        if (a[i] == b[i] && a[i] >= 'A' && a[i] <= 'N') {
            ho = a[i] - 'A' + 10;
            break;
        } else if (a[i] == b[i] && a[i] >= '0' && a[i] <= '9') {
            ho = a[i] - '0';
            break;
        }
    }
    for (i = 0; i < n; i++) {
        if (c[i] == d[i] && ((c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'))) {
            mi = i;
            break;
        }
    }
    printf("%s %02d:%02d\n", date[da], ho, mi);

    return 0;
}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页