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

华为机试:星期几的问题

时间:2014-12-29 01:21:45      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:华为

1990年1月1日 是星期一,
输入:1990 1 1  输出 monday

输入:2013 9 17 输出 tuesday


#include<cstdio>
#include<cstring>
char *weeks[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
void zeller(int y,int m,int d){
    if(m<=2)
    {
        y--;
        m+=12;
    }
    int c=y/100;
    y=y%100;
    int w=y+y/4+c/4-2*c+(26*(m+1)/10)+d-1;
    while(w<0)w+=7;
    printf("%s\n",weeks[w%7]);
}
int main(int argc, char *argv[])
{
    int y,m,d;
    while(~scanf("%d %d %d",&y,&m,&d))
    {
        zeller(y , m , d);
    }
    return 0;
}



华为机试:星期几的问题

标签:华为

原文地址:http://blog.csdn.net/wdkirchhoff/article/details/42122267

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