Problem Description
Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?
Input
There are multiply cases.
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
Output
Output one line.
if the date is illegal, you should output "illegal". Or, you should output what day it is.
if the date is illegal, you should output "illegal". Or, you should output what day it is.
Sample Input
2007 11 17
Sample Output
Saturday这是一道很无聊的题,难怪正确率那么低,突破点在于公元元年1月1号是周一,只需要求只一天离公元元年有多少天即可,注意题中所说“如果输入违法,请输出illegal”就因为这一句 贡献了三次wa.#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int i,n,j,k,l,leap,m,d,y; char s[8][100]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};//把日期存进字符数组 int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};//月份的天数存入数组 int run(int x) { if((x%4==0&&x%100!=0)||x%400==0) return 1;//判断是否为闰年 return 0; } int main() { while(scanf("%d%d%d",&y,&m,&d)!=EOF) { long sum=0; if(m==0||d==0||(m==2&&d>29)||(!((y%4==0&&y%100!=0)||y%400==0)&&m==2&&d>28)) { printf("illegal\n"); continue; }//如果日期非法 if(m==4||m==6||m==9||m==11) { if(d>30) { printf("illegal\n"); continue; } }//如果日期非法 if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) { if(d>31) { printf("illegal\n"); continue; } }//如果日期非法 for(i=1;i<y;i++) { if(run(i)) sum=sum+366; else sum=sum+365; }//判断到所输入的前一年离公元元年相差多少年 for(i=0;i<m-1;i++) sum=sum+a[i];//判断输入年份是当年的第几天 sum=sum+d; if(run(y)&&m>2) sum++; k=sum%7;//判断是周几. printf("%s\n",s[k]); } return 0; }
Problem Description
Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?
Input
There are multiply cases.
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
Output
Output one line.
if the date is illegal, you should output "illegal". Or, you should output what day it is.
if the date is illegal, you should output "illegal". Or, you should output what day it is.
Sample Input
2007 11 17
Sample Output
Saturday