#2629: Finally I got AC

Unknown User


這題例外還真多...

#include <stdio.h>
#include <stdlib.h>

int year, month, date;
int m, d;
int R;        //閏年
int b_s_2;
//big month, small month or Feb.(Not the NCTU's BBS station XDD)
//val: Feb = 2, big = 1, small = 0

int check () {
    if (m == month && d == date) return 1;
    else return 0;
}

int leap_year () {
    if(year % 4 == 0 && year % 100 != 0)
        return 1;
    else if(year % 400 == 0)
        return 1;
    else
        return 0;
}

int main () {
    int ctr=0;
    while (scanf ("%d%d%d", &year, &month, &date) != EOF) {
        /*--偷偷拿來抓測資的 block---------------------------*
        char str[15];
        ctr++;
        if (ctr == 5) {
            sprintf(str, "%d %d %d", year, month, date);
            puts(str);
        }
        /*-----------------------------*/
        R = leap_year();
        //所有數據不能小於等於零
        if (year <= 0 || month <= 0 || date <= 0) {
            puts("Error");
            continue;
        }
        //沒有13月啦!! 第四行
        if (month > 12) {
            puts("Error");
            continue;
        }


        if (month == 2) {        //二月例外處理
            if (R) {
                if (date > 29) {
                    printf("Error\n");
                    continue;
                }
            }
            if (!R) {
                if (date > 28) {
                    printf("Error\n");
                    continue;
                }
            }
        }

        else if (month == 1 || month == 3 || //大月
                 month == 5 || month == 7 ||
                 month == 8 || month == 10 || month == 12) {
                if (date > 31) {
                    printf("Error\n");
                    continue;
                }
        }
        else {        // 小月
            if (date > 30) {
                printf("Error\n");
                continue;
            }
        }
        //=接下來做第幾天的判斷==========================
        int i, j, ans;
        ans  = 0;
        for (i = 1; i <= 12; i++) {
            if (i == 2) {        //Feb.
                b_s_2 = 2;
            }
            else if (i == 1 || i == 3 || //大月
                     i == 5 || i == 7 ||
                     i == 8 || i == 10 || i == 12) {
                b_s_2 = 1;
            }
            else {
                b_s_2 = 0;
            }
                
            for (j = 1; j <= 31; j++) {
                if (b_s_2 == 2) {        //Feb.
                    if (R) {
                        if (j > 29) {
                            break;
                        }
                    }
                    if (!R) {
                        if (j > 28) {
                            break;
                        }
                    }
                    ans++;    //one more day
                    m = i;
                    d = j;
                    if (check()) {
                        printf("It is %d days in %d", ans, year);
                    }
                }
                else if (b_s_2 == 1) {            //big month
                    ans++;    //one more day
                    m = i;
                    d = j;
                    if (check()) {
                        printf("It is %d day", ans);
                        if(ans != 1) printf("s");
                        printf(" in %d", year);
                    }
                }
                else {                    //small month
                    if (j > 30) {
                        break;
                    }
                    ans++;    //one more day
                    m = i;
                    d = j;
                    if (check()) {
                        printf("It is %d days in %d", ans, year);
                    }
                    
                }
            }
        }
        puts("");    //new line
    }
    return 0;
}