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

20minutes.1AbaneHunter

Posted by 1340502116 at 2016-07-04 21:55:36 on Problem 2080
#include <iostream>
using namespace std;
int mds[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char Week[8][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
bool isLeap(int year)
{
	if((year%4==0&&year%100!=0)||year%400==0)
	{
		return true;
	}
	return false;
}
int main()
{
	int standard=0;
	for(int i=2000;i<=2015;i++)	
	{
		if(isLeap(i))	standard+=366;
		else	standard+=365;	
	}
	for(int i=1;i<=6;i++)
	{
		standard+=mds[i];
	}
	if(isLeap(2016))	standard++;
	standard+=3;
	int diff;
	int days;
	while(cin>>days&&days!=-1)
	{
		diff=days-standard;
		diff++;
		int year=2000;
		int d=1;
		int m=1;
		while(true)
		{
			if(isLeap(year))
			{
				if(days>=366)
				{
					days-=366;
					year++;
				}
				else	break;
			}	
			else
			{
				if(days>=365)
				{
					days-=365;
					year++;
				}
				else	break;
			}
		}
		while(true)
		{
			int ms=mds[m];
			if(isLeap(year)&&m==2)
			{
				ms++;
			}
			if(days>=ms)
			{
				days-=ms;
				m++;
			}
			else	break;
		}
		d+=days;
		cout<<year<<"-";
		if(m<10)	cout<<"0";
		cout<<m<<"-";
		if(d<10)	cout<<"0";
		cout<<d<<" ";
		
		if(diff>=0)
		{
			diff%=7;
			cout<<Week[diff]<<endl;
		}
		else
		{
			diff=-diff;
			diff%=7;
			if(diff==0)	diff=7;
			cout<<Week[7-diff]<<endl;
		}
	}
	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