Calendar - SGU 115(日期判断)

这年的开始的第一天是星期 1

 

代码如下:

========================================================================================================

#include<stdio.h>
#include<algorithm>
#include<vector>
#include<iostream>
#include<math.h>
#include<string.h>
using namespace std;

///平年
int M[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int Week(int date, int month)
{
    int w=date;

    if(month>12 || month<1 || date<1 || date > M[month])
        return -1;

    for(int i=1; i<month; i++)
        w += M[i];

    return (w%7) ? (w%7) : 7;
}

int main()
{
    int date, month;

    scanf("%d%d", &date, &month);

    int w = Week(date, month);

    if(w < 0)
        printf("Impossible\n");
    else
        printf("%d\n", w);

    return 0;
}

 

posted @ 2015-09-17 11:29  无忧望月  阅读(98)  评论(0编辑  收藏  举报
levels of contents