上海交通大学 Day of Week

#include<bits/stdc++.h>
#define ISYEAP(x) x%4==0&&x%100!=0||x%400==0?1:0
using namespace std;
int daymonth[13][2]={
    0,0,
    31,31,
    28,29,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31,
    31,31,
    30,30,
    31,31,
    30,30,
    31,31
};
char weekday[8][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char monthname[13][20]={" ","January","February","March","April","May","June","July","August","September","October","November","December"};
struct date{
    int year;
    int month;
    int day;
    void nextday(){
        day++;
        if(day>daymonth[month][ISYEAP(year)]){
            day=1;
            month++;
            if(month>=13){
                month=1;
                year++;
            }
        }
    }
};
int buf[3001][13][32];
int main(){
    date temp;
    temp.year=0;
    temp.day=1;
    temp.month=1;
    int year,day;
    char month[20];
    int count=0;
    while(temp.year!=3001){
        buf[temp.year][temp.month][temp.day]=count;
        temp.nextday();
        count++;
    }
    while(scanf("%d %s %d",&day,&month,&year)!=EOF){
        int m;
        for(int i=1;i<=12;i++)
            if(strcmp(month,monthname[i])==0){
                m=i;
                break;
            }
        int start=4;
        int ans=buf[year][m][day]-buf[2018][5][3];
        int t=((ans+start)%7+7)%7;
        printf("%s\n",weekday[t]);
    }
    return 0;
}









猜你喜欢

转载自blog.csdn.net/qq_31674679/article/details/80181971