POJ-3047

Bessie asked her friend what day of the week she was born on. She knew that she was born on 2003 May 25, but didn't know what day it was. Write a program to help. Note that no cow was born earlier than the year 1800. 

Facts to know: 

* January 1, 1900 was on a Monday. 

* Lengths of months: 
    Jan 31          May 31      Sep 30
    Feb 28 or 29    Jun 30      Oct 31
    Mar 31          Jul 31      Nov 30
    Apr 30          Aug 31      Dec 31

* Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year). 

* The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.
Input
* Line 1: Three space-separated integers that represent respectively the year, month (range 1..12), and day of a date.
Output
* Line 1: A single word that is the day of the week of the specified date (from the lower-case list: monday, tuesday, wednesday, thursday, friday, saturday, sunday).
Sample Input
2003 5 25
Sample Output
sunday
Hint
INPUT DETAILS: 
May 25, 2003 

OUTPUT DETAILS: 
      May 2003
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

    一个简单的判断某年某月某日是周几的题,是从1800年开始的,注意不是1900年。算一下1800.1.1到要求的那天总天数,对7求余数,根据1800.1.1是周几判断就好了。至于1800.1.1是怎么来的,可以根据1900.1.1是sunday算,我偷了个懒,百度万年历哈哈。

代码如下:

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int year,month,day;
    int mot[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    while(cin>>year>>month>>day)
    {
        int sum=0;
        for(int i=1800;i<year;i++)
        {
            sum+=365;
            if((i%4==0 && i%100!=0) || i%400==0)
            {
                sum+=1;
            }
        }
        for(int j=1;j<month;j++)
        {
            sum+=mot[j-1];
        }
        if(month>2)
        {
            if((year%4==0 && year%100!=0) || year%400==0)
            {
                sum++;
            }
        }
        sum+=day;
        sum--;
        if(sum%7==5)
            cout<<"monday"<<endl;
        if(sum%7==6)
            cout<<"tuesday"<<endl;
        if(sum%7==0)
            cout<<"wednesday"<<endl;
        if(sum%7==1)
            cout<<"thursday"<<endl;
        if(sum%7==2)
            cout<<"friday"<<endl;
        if(sum%7==3)
            cout<<"saturday"<<endl;
        if(sum%7==4)
            cout<<"sunday"<<endl;
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值