码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-06-24 15:36:25      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:code   oid   include   ret   九度   arc   abs   oct   return   

 

 

#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

标签:code   oid   include   ret   九度   arc   abs   oct   return   

原文地址:http://www.cnblogs.com/kprac/p/7073383.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!