Calendar

这年的开始的第一天是星期 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
");
    else
        printf("%d
", w);

    return 0;
}
原文地址:https://www.cnblogs.com/liuxin13/p/4815828.html