mltang

博客园 首页 新随笔 联系 订阅 管理

给你个日期 问是星期几        知道1 1 1是周1就行了

 

 

 

#include <iostream>
#include <cstdio>
using namespace std;
int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
char str[7][100] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
bool run(int x);
int main()
{
    int a,b,c,i,j,sum = 0;
    int Y = 2007,M = 11,D = 17,R = 6;
    for(i =0; i < 2007; ++i)
        if(run(i))
    while(scanf("%d%d%d",&a,&b,&c) != EOF)
    {
        long long sum = 0;
        if(b == 0 || c == 0 || (b == 2 && c > 29 && run(a)) || (b == 2 && c > 28 && !run(a)) || (c > arr[b] && b != 2) )
        {
            cout << "illegal" << endl;
            continue;
        }
        for(i = 1; i < a; ++i)
        {
            if(run(i)) sum += 366;
            else sum += 365;
        }
        for(i = 1; i <= b-1; ++i)
        {
            sum += arr[i];
        }
        if(run(a) && b > 2)
            sum ++;
        sum += c;
        sum= sum%7;
//        if(!sum) sum = 7;
        cout << str[sum] << endl;
    }
}
bool run(int x)
{
    if((x % 4 == 0 && x % 100 != 0)|| x%400 == 0)
        return true;
    else
        return false;
}

posted on 2018-04-02 17:24  mltang  阅读(90)  评论(0编辑  收藏  举报