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

我自己的答案,AC,157MS,仅供参考!

Posted by CatLovers at 2014-07-28 16:13:24 on Problem 2080
#include<stdio.h>

bool isLeapYear(int year)
{
	if( (year %4 ==0 && year %100 !=0) || (year %400 ==0 ) )
		return true;
	return false;
}

void process(int days)
{
	/*data structure*/
int dayInWeek = (5 + days %7) %7;
int year,month,day;
int daysOfYear[2] ={365,366};
int daysOfMonth[2][12] ={{31,28,31,30,31,30,31,31,30,31,30,31},
							{31,29,31,30,31,30,31,31,30,31,30,31}};
char week[7][10] ={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

	for(year =2000; days >= daysOfYear[ isLeapYear(year) ];year++)	//处理year
		days -= daysOfYear[ isLeapYear(year) ];
	int isLeap =(int)isLeapYear(year);
	for(month=0;days >= daysOfMonth[ isLeap ][month];month++)
		days -= daysOfMonth[isLeap ][month];
	month++;
	day =days+1;
	//output
	printf("%d-",year);
	if( month < 10 )
		printf("0%d-",month);
	else 
		printf("%d-",month);
	if( day < 10 )
		printf("0%d ",day);
	else
		printf("%d ",day);
	printf("%s\n",week[dayInWeek]);
}

int main()
{
	int days;
	while( scanf("%d",&days)!=EOF && days !=-1 )
		process(days);

	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