九度OJ 题目1043:Day of Week

原创 2012年03月27日 19:41:53

本算法中引用的是由Tomohiko Sakamoto 提供的简洁函数代码

代码如下:

int dayofweek(int y, int m, int d) /* 0 = Sunday */
{
       static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
       y -= m < 3;
       return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

AC代码如下:

#include <stdio.h>

int dayofweek(int y, int m, int d) /* 0 = Sunday */
{
       static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
       y -= m < 3;
       return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}

const char day[][20] = {"Sunday","Monday","Tuesday","Wednesday",
                    "Thursday","Friday","Saturday"};

const char month[][20] = {"January", "February", "March", "April",
                    "May", "June", "July", "August", "September",
                     "October", "November", "December"};

int main()
{
    char m[20];
    int d,y,mon;
    int i;
    while(scanf("%d %s %d",&d,m,&y) != EOF)
    {
        for(i = 0;i < 12;i++)
        {
            if(strcmp(m,month[i]) == 0)
            {
                mon = i;
                break;
            }
        }
        //printf("%d %d %d\n",y,mon + 1,d);
        printf("%s\n",day[dayofweek(y,mon + 1,d)]);
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

题目1043:Day of Week

import java.io.IOException; import java.util.Scanner; import java.io.FileReader; import java.io.Buff...

题目1043:Day of Week

题目1043:Day of Week 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7119 解决:2507 题目描述: We n...

九度OJ 题目1043:Day of Week

题目描述: We now use the Gregorian style of dating in Russia. The leap years are years with number di...

九度OJ 1043:Day of Week(星期几) (日期计算)

时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5349 解决:1923 题目描述: We now use the Gregorian style...

九度OJ-1043:Day of Week

题目描述: We now use the Gregorian style of dating in Russia. The leap years are years with number di...

九度OJ 1043 Day of Week

原题地址:http://ac.jobdu.com/problem.php?pid=1043题目描述: We now use the Gregorian style of dating in Russ...

九度题目1043:Day of Week

原题链接:http://ac.jobdu.com/problem.php?pid=1043 题目描述: We now use the Gregorian style of dating in Russ...

[日期类问题] 例 2.4 Day of week(九度教程第 7 题)

题目时间限制:1 秒 内存限制:32 兆 特殊判题:否题目描述: We now use the Gregorian style of dating in Russia. The lea...

九度 oj 题目1446:Head of a Gang

http://ac.jobdu.com/problem.php?pid=1446 参考了 http://blog.csdn.net/jdplus/article/details/19759729 并...

九度OJ 题目1446:Head of a Gang

一.题目描述  One way that the police finds the head of a gang is to check people's phone calls. If there ...
  • lhyer
  • lhyer
  • 2015年08月10日 14:58
  • 564
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:九度OJ 题目1043:Day of Week
举报原因:
原因补充:

(最多只允许输入30个字)