您的位置:首页 > 其它

OJ_1043 Day of Week

2014-02-16 09:27 295 查看
#include <iostream>
#include <map>
using namespace std;
bool isLeap(int y)
{
if(y%4==0&&y%100!=0)
return true;
if(y%400==0)return true;
return false;
}
int monint[12]={0,31,28,31,30,31,30,31,31,30,31,30};
map<string,int> mon;
map<int,string> week;
void initMap()
{
for(int i=1;i<12;i++)
{
monint[i]=monint[i]+monint[i-1];
}
int j=0;
mon["January"]=monint[j++];
mon["February"]=monint[j++];
mon["March"]=monint[j++];
mon["April"]=monint[j++];
mon["May"]=monint[j++];
mon["June"]=monint[j++];
mon["July"]=monint[j++];
mon["August"]=monint[j++];
mon["September"]=monint[j++];
mon["October"]=monint[j++];
mon["November"]=monint[j++];
mon["December"]=monint[j++];

j=0;
week[j++]="Sunday";
week[j++]="Monday";
week[j++]="Tuesday";
week[j++]="Wednesday";
week[j++]="Thursday";
week[j++]="Friday";
week[j++]="Saturday";
}
void func()
{
initMap();
int d,y;
string m;
while(cin>>d>>m>>y)
{
int sumday=0;
int yday=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400;
sumday=yday+mon[m]+d;
int weekint=sumday%7;
cout<<week[weekint]<<endl;

}

}
int main(int argc, char *argv[])
{

//printf("Hello, world\n");
func();
return 0;
}


计算输入日期距离元年元月元日(按算法这一天是星期一)有多少天,然后取模

不考虑历史上格历高历确定星期后出现的问题

题目描述:

We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.

For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.

Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.

输入:

There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.

输出:

Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

样例输入:
9 October 2001
14 October 2001


样例输出:
Tuesday
Sunday


提示:

Month and Week name in Input/Output:

January, February, March, April, May, June, July, August, September, October, November, December

Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: