Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:自己写的 + 参考他的

Posted by huanghaoxiang at 2009-10-05 23:32:22 on Problem 2080
In Reply To:Re:实在是 不容易啊 ~ 终于 AC~ Posted by:huanghaoxiang at 2009-10-05 23:04:33
> 谢谢

#include<stdio.h>

char *str[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

int  day2( int month,int day1 )
{
	if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 )
		return 31;
	else if ( month == 2 )
	{ 
		if ( day1 == 366 )
			return 29;
		else return 28;
	}
	else return 30;
}


int main()
{
	int day;
	while ( scanf ( "%d",&day ) )
	{
		if ( day == -1 )
			break;
		int w = day;
		day++; // 因为从1.1号在一起,如果输入1 是 1.2
		int month,week,n,year;
		int day1;
		year = 2000;
		while( day > 366 ) //求年
		{
			if(( year % 4== 0 && year % 100 !=0 )|| year % 400 == 0)
				day-=366;
			else day-=365;
			year++;
		}
		int day3;
		if (  ( year % 4== 0 && year % 100 !=0 )|| year % 400 == 0 )
			day1 = 366;
		else day1 = 365;
		if ( day1 != 366  ) // 不是闰年的时候
		{
			if ( day == 366 ) // 如果不是闰年 366 是下一个月 第一天
			{
				year++;
				day -= 365;
			}
		}
		for ( month = 1; month != 13; ++month ) // 一个一个月减
		{
			day3 = day2( month,day1 );
			if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 )
			{
				if ( day <= 31 )
					break;
			}
			else if ( month == 2 )
			{
				if ( day1 == 366 )
				{
					if ( day <= 29 )
						break;
				}
				else
				{
					if ( day < 29 )
						break;
				}
			}
			else 
			{
				if ( day <= 30 )
					break;
			}
			day -= day3;
		}
		printf ( "%d-%02d-%02d %s\n",year,month,day,str[(w+6)%7] );
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator