oj---九度oj---1043----day of week

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oj---九度oj---1043----day of week相关的知识,希望对你有一定的参考价值。

 

 

#include<cstdio>
#include<cstring>
int isleap(int n){
    if((n%100!=0&&n%4==0)||n%400==0)
        return 1;
    else return 0;
}
int dayofmonth[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 monthname[13][20]={
    "",
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
};
char dayname[7][20]={
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"
};
struct date{
    int d;
    int m;
    int y;
    void nextday(){
        d++;
        if(d>dayofmonth[m][isleap(y)]){
            m++;
            d=1;
        
            if(m>12){
                m=1;
                y++;
            }
        }
    }
};

int process[5005][13][32];
int abs(int x){
    return x<0?-x:x;
}
int main(){
    date tmp;
    int cnt=0;
    tmp.d=1;
    tmp.m=1;
    tmp.y=0;
    while(tmp.y!=5001){
        process[tmp.y][tmp.m][tmp.d]=cnt;
        tmp.nextday();
        cnt++;
    }

    int d,m,y;
    char s[20]; 

    while(scanf("%d%s%d",&d,s,&y)!=EOF){
        for(m=1;m<=12;m++){
            if(strcmp(s,monthname[m])==0)
                break;
        }

    int days=process[y][m][d]-process[2017][6][25];
    puts(dayname[(days%7+7)%7]);
    }
    return 0;
}

 

以上是关于oj---九度oj---1043----day of week的主要内容,如果未能解决你的问题,请参考以下文章

九度OJ平台练习 —— 题目1011

九度oj1002

oj---九度oj---1061

oj---九度oj---1433

oj---九度oj---1434

oj---九度oj---1015