SGU 115. Calendar

2001年某月某号星期几

到那天天数%7+1  然后修正到正确日期再 %7

SGU 115. Calendar
/*************************************************************************
    > File Name:    sgu115.cpp
    > Author:       Shine
    > Created Time: 2013-05-06 下午 6:24:01
    > QuestionType: 模拟
    > Way: 
    > Submit: 1WA(很不应该,没自己检验,就交,公式错误) 1AC
    > Gain: None
    > Experience: 交前负责啊。。检验一下不会死的啊
 ************************************************************************/
#include <cstdio>
#define FIRSTDAY -1
//Monday - Sunday : 0 - 6

int month[13]={0};
int m[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

void predo() {
    int i;
    for (i = 1; i <= 12; i++) {
        month[i] = month[i-1] + m[i];
    }
}

int check(int m, int d) {
    switch(m){
        case 2:
            if (d >= 0 && d <= 28) return 1;
            else return 0;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            if (d >= 0 && d <= 31) return 1;
            else return 0;
        case 4:
        case 6:
        case 9:
        case 11:
            if (d >= 0 && d <= 30) return 1;
            else return 0;
        default:
            return 0;
    }
}

int main(){
    predo();
    int d, m;
    while (scanf("%d%d", &d, &m) != EOF) {
        if (check(m, d) == 0) puts("Impossible");
        else printf("%d\n", (month[m-1]+d+FIRSTDAY)%7+1);
    }
    return 0;
}
        

 

posted on 2013-05-06 18:44  ShineCheng  阅读(127)  评论(0编辑  收藏  举报

导航