杭电2133What day is it



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).
 

Output
Output one line.
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).
 

Output
Output one line.
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值