码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1061. Dating

时间:2014-11-23 23:08:53      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   on   div   log   

题是别人出的,不按她的想法来也没办法,真心想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;
}

 

PAT 1061. Dating

标签:style   blog   io   ar   color   sp   on   div   log   

原文地址:http://www.cnblogs.com/lailailai/p/4117639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!