150 - Double Time

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

turboc
New poster
Posts: 2
Joined: Mon Dec 17, 2001 2:00 am
Contact:

Post by turboc » Mon Dec 17, 2001 7:05 am

I thought I was correct, but always get Wronganswer

..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. » Sat Jan 05, 2002 6:34 pm

Can anyone explain this to me?
I don't understand which conversion I should do?

not-corrected for 11days<=> Roman Catholic countries
not-corrected for 11days<=> British and Americans
Roman Catholic countries <=> British and Americans
Roman Catholic countries & British and Americans <=> not-corrcted for 11days

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Thu Jan 31, 2002 3:40 pm

Hi!

This is a very strange thing because it means nothing !!!

The only thing you should know is that
5 October 1582(friday) is 15 October 1582 (Friday)

First date is in Julius Ceasar's calendar and the second one is Roman Catolics. From this date you should start counting according to rules that are in the task

Good Luck :smile:

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Thu Jan 31, 2002 3:54 pm

Hi!

Don't give up :smile:

It is not vey diffucult...

You have only to remember about rules and look out because, in the output the dates may be "later" that 2099....

That is all....
The difference beetween two times increases one day per 100 years (except years 1600,2000).
So you only have to check whether the date is in first or in the second time and add the correct number of days....

I hope it will help you.

Good Luck :smile:

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post by wyvmak » Sat Feb 23, 2002 1:29 pm

would someone give me the output for:

Tuesday 11 January 1600
Thursday 1 March 1900
Monday 1 January 2001

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi » Sat Feb 23, 2002 2:36 pm

The output is:
Tuesday 1* January 1600
Thursday 17* February 1900
Monday 19* December 2000
(but there is a # in input at EOF: I was shocked when my program hanged first)

Orgi
New poster
Posts: 11
Joined: Mon Oct 29, 2001 2:00 am
Location: Bulgaria

150 - Double Time

Post by Orgi » Fri May 17, 2002 6:01 pm

Could anybody tell me what was changed in the rejudgement...
i keep getting WA but before that it was AC

are there any hidden tricks, in the input for example

Thank you.

rascle
New poster
Posts: 20
Joined: Wed Mar 06, 2002 2:00 am

150 help me

Post by rascle » Sat Jul 13, 2002 5:34 pm

My program got WA...
Can you give me some inputs and outputs ..

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

[150]WA

Post by FlyDeath » Wed Jan 22, 2003 3:01 pm

My method is building up a array that denote each day in both old and new style.Suppose that 1 January 1600 in new style is the first day(=22 December 1599 in old style),and so on.

I've checked almost every test data.(I used a program to print everyday from 1 January 1600 to 31 December 2099).And It looked fine(I just skim throuth the result.It was to much!).Can someone compile this program under linux shell?(I'm using Windows XP)Maybe the program act weird under linux :X (or maybe it was just my spelling mistake?)

Here is my code



[cpp]
#include <stdio.h>
#include <string.h>
#define BASE 5
#ifndef bool
#define bool int
#endif

/* newptr store the date of new style,oldptr store thr date of old style */
int newptr[3];
int oldptr[3];
const int monthmax[12]={31,28,31,30,31,30,31,31,30,31,30,31};
const char weekname[7][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
const char monthname[12][20]={"January","Febuary","March","April","May","June","July","August","September","October","November","December"};

/* check if the date is after 31 December 2099 in old style */
int oldoverflow()
{
if(oldptr[0]>=2100)
return 1;
else
return 0;
}

/* calculate the next day in new style */
void addnew()
{
newptr[2]++;
if(newptr[1]==1)
{
if(newptr[0]%4==0)
{
if(newptr[0]%100==0)
{
if(newptr[0]%400==0)
{
if(newptr[2]>=29)
{
newptr[2]=0;
newptr[1]++;
}
}
else
{
if(newptr[2]>=28)
{
newptr[2]=0;
newptr[1]++;
}
}
}
else
{
if(newptr[2]>=29)
{
newptr[2]=0;
newptr[1]++;
}
}
}
else
{
if(newptr[2]>=28)
{
newptr[2]=0;
newptr[1]++;
}
}
}
else
{
if(newptr[2]>=monthmax[newptr[1]])
{
newptr[2]=0;
newptr[1]++;
}
}
if(newptr[1]>=12)
{
newptr[1]=0;
newptr[0]++;
}
}

/* calculate the next day in old style */
void addold()
{
oldptr[2]++;
if(oldptr[1]==1)
{
if(oldptr[0]%4==0)
{
if(oldptr[2]>=29)
{
oldptr[2]=0;
oldptr[1]++;
}
}
else
{
if(oldptr[2]>=28)
{
oldptr[2]=0;
oldptr[1]++;
}
}
}
else
{
if(oldptr[2]>=monthmax[oldptr[1]])
{
oldptr[2]=0;
oldptr[1]++;
}
}
if(oldptr[1]>=12)
{
oldptr[1]=0;
oldptr[0]++;
}
}


void main()
{
long i,j,k;
bool flag;
char week[20];
char month[20];
int day;
int year;
int monthnum;
int weeknum;
newptr[0]=1600;
newptr[1]=0;
newptr[2]=0;
oldptr[0]=1599;
oldptr[1]=11;
oldptr[2]=21;
for(i=0;i<2100;i++)
{
for(j=0;j<12;j++)
{
for(k=0;k<31;k++)
{
newday[j][k]=-1;
oldday[j][k]=-1;
}
}
}
for(i=1;;i++)
{
oldday[oldptr[0]][oldptr[1]][oldptr[2]]=i;
newday[newptr[0]][newptr[1]][newptr[2]]=i;
addnew();
addold();
if(oldoverflow()==1)
break;
}
while(scanf("%s",&week)!=EOF)
{
if(week[0]=='#')
break;
scanf("%d %s %d",&day,&month,&year);
day--;
for(i=0;i<7;i++)
{
if(strcmp(week,weekname)==0)
{
weeknum=i;
break;
}
}
for(i=0;i<12;i++)
{
if(strcmp(month,monthname)==0)
{
monthnum=i;
break;
}
}
if(newday[year][monthnum][day]!=-1&&(newday[year][monthnum][day]+BASE)%7==weeknum)
{
flag=0;
i=year;
j=monthnum;
k=day;
for(;flag==0;i--)
{
for(;j>=0&&flag==0;j--)
{
for(;k>=0&&flag==0;k--)
{
if(oldday[j][k]==newday[year][monthnum][day])
{
flag=1;
break;
}
}
if(flag==0)
k=30;
else
break;
}
if(flag==0)
j=11;
else
break;
}
printf("%s %d* %s %d\n",week,k+1,monthname[j],i);
}
else if(oldday[year][monthnum][day]!=-1&&(oldday[year][monthnum][day]+BASE)%7==weeknum)
{
flag=0;
i=year;
j=monthnum;
k=day;
for(;flag==0;i++)
{
for(;j<12&&flag==0;j++)
{
for(;k<31&&flag==0;k++)
{
if(newday[j][k]==oldday[year][monthnum][day])
{
flag=1;
break;
}
}
if(flag==0)
k=0;
else
break;
}
if(flag==0)
j=0;
else
break;
}
printf("%s %d %s %d\n",week,k+1,monthname[j],i);
}
}
}
[/cpp]

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Wed Jan 22, 2003 3:56 pm

OH MY GOD!!

I misspell February :( (I writed it as "Febuary" before)

Don't bother with this question anymore.(I guess what I really need is to improve my English :cry: )

Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:

Post by Whinii F. » Fri Jul 11, 2003 8:07 pm

I'm totally confused about this problem for quite a while.
Am I really understanding it correctly?

To my comprehension,

1. (Russia did not change until 1918, and Greece waited until 1923.) This statement does nothing but confuses me. Should I only consider two systems one changed after 1582 and one changed after 1752?

2. Is the one changed after 1582 the "new" system?

3. There are no differences up to 1582 Oct 4. Then the old calender has 10 extra days. And after that the only difference between two calenders is 1700 Feb 29 (Which is counted in the old calender and not in the new calender). So in 1752 Sep 2 the new calender is 11 days faster than the old one. Then the new calender has 11 extended days (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13). So after that the two calenders are not distinguishable.

Am I right?
I'm totally confused :(
JongMan @ Yonsei

Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:

Post by Whinii F. » Tue Jul 15, 2003 6:31 am

Oh I was a stupid.. from reskimming FlyDeath's post I found out what was wrong. :(
JongMan @ Yonsei

User avatar
Masud_CSE_SUST
New poster
Posts: 11
Joined: Sat Jul 22, 2006 8:45 pm
Location: Sylhet, Bagladesh
Contact:

150 (Double time) WA! Give some input & output

Post by Masud_CSE_SUST » Sun Jul 30, 2006 10:56 pm

Too few post/conversation about 150 ( Double Time )
Dear helpers please help. Give some critcal input & output

User avatar
Masud_CSE_SUST
New poster
Posts: 11
Joined: Sat Jul 22, 2006 8:45 pm
Location: Sylhet, Bagladesh
Contact:

Post by Masud_CSE_SUST » Thu Aug 03, 2006 5:59 pm

Why no reply yet . Please Help !!!!!!!!

Lucas.Mannell
New poster
Posts: 1
Joined: Thu Aug 10, 2006 8:07 am

Post by Lucas.Mannell » Thu Aug 10, 2006 8:17 am

I'm getting a Wrong Answer result for this problem as well. I've tested it against the supplied example I/O, and several dates gleaned from online and offline date converters I found. I've always come up with correct results. Can anyone point me in the right direction?

Code is as follows (It's huge, sorry)

Code: Select all

/*
*	Filename: 	DoubleTime.cpp
*	Programmer:	Lucas Mannell
*	Date:		August 9th, 2006
*	Comments:	My solution to UVA's "Double Time" Calendar problem,
*				Problem number 150
*/

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstdlib>
#include <iomanip>

using namespace std;

void stringCapitalize(string& s);

class Date
{
	public:
		Date(string day, int date, string month, const char year[]);
		void testStyle();
		void Convert();
		friend ostream& operator<<(ostream& outS, Date& D); 		
	private:
		int year;
		int twoDigitYear;
		int day;
		//int monthNumber;
		int newDay;			//In case the date needs to be changed
		int newMonth;
		int newYear;		//In case the year over- or under-flows
		string month;
		string dayOfWeek;
		string newMonthName;	//In case the month over- or under-flows
		string newDayOfWeek;//In case the  day needs to change
		bool isJulian;
		bool isLeapYear;
		//Incidental variables for the conversion algorithm.
		int dayNumber;
		int monthKeyValue;
		int JulianOffset;
		int GregorianOffset;		
};

int main()
{
	vector< Date > dates;
	
	int initialDay, numDates;
	numDates = 0;
	string initialDayOfWeek, initialMonth, initialYear;
	
	cin >>  initialDayOfWeek;
	cin.ignore(1, ' ');
	stringCapitalize(initialDayOfWeek);
	cin >> initialDay;
	cin.ignore(1, ' ');
	cin >> initialMonth;
	cin.ignore(1, ' ');
	stringCapitalize(initialMonth);
	cin >> initialYear;
	cin.ignore(1, ' ');
	stringCapitalize(initialYear);
	
	while(initialDayOfWeek != "#")
	{
		Date date(initialDayOfWeek, initialDay, initialMonth, initialYear.c_str());
		dates.push_back(date);
		cin >> initialDayOfWeek;
		cin.ignore(1, ' ');
		stringCapitalize(initialDayOfWeek);
		if(initialDayOfWeek != "#")
		{
			cin >> initialDay;
			cin.ignore(1, ' ');
			cin >> initialMonth;
			cin.ignore(1, ' ');
			stringCapitalize(initialMonth);
			cin >> initialYear;
			cin.ignore(1, ' ');
			stringCapitalize(initialYear);
		}
		numDates++;
	}
	
	for(int i = 0; i < numDates; i++)
	{
		dates[i].testStyle();
		dates[i].Convert();
	}
	
	for(int i = 0; i < numDates; i++)
	{
		cout << dates[i];
		if(i != numDates)
		{
			cout << endl;
		}
	}
	
	//cin.clear();
	//cin.ignore(80, '\n');	
	return 0;
}

void stringCapitalize(string& s)
{
	if(s.at(0) >= 'a' && s.at(0) <= 'z')
	{
		s.at(0) -=32;
	}
}

ostream& operator<<(ostream& outS, Date& D)
{
	outS << D.dayOfWeek << " ";
	
	outS << D.newDay;
	
	if(!D.isJulian)//If not originally Julian
	{
		outS << "*";
	}
	outS << " ";
	
	if(D.month != D.newMonthName)
	{
		outS << D.newMonthName << " ";
	}
	else
	{
		outS << D.month << " ";
	}
	
	outS << D.newYear;
	
	return outS;
}

Date::Date(string day, int date, string month, const char year[])
{
	this->day = date;
	this->year = 0;
	char twoDigit[3];
	this->twoDigitYear = 0;
	
	//The 4-digit year is stored as a string because I want
	//getting both the 4- and 2-digit years a quick and
	//painless process.
	this->year += atoi( year );
	twoDigit[0] = year[2];
	twoDigit[1] = year[3];
	
	this->twoDigitYear += atoi( twoDigit );
	
	this->month = month;
	this->dayOfWeek = day;
	
	this->dayNumber = -1;
	
	//setting month key values and day values.
	//Referenced math tutorial: 
	//http://www.mcs.csuhayward.edu/~malek/Mathlinks/Weekdays.html
	if(this->month == "January" || this->month == "October")
	{
		this->monthKeyValue = 1;
	}
	else if(this->month == "February" || this->month == "March" || 
			this->month == "November")
	{
		this->monthKeyValue = 4;
	}
	else if(this->month == "April" || this->month == "July")
	{
		this->monthKeyValue = 0;
	}
	else if(this->month == "May")
	{
		this->monthKeyValue = 2;
	}
	else if(this->month == "June")
	{
		this->monthKeyValue = 5;
	}
	else if(this->month == "August")
	{
		this->monthKeyValue = 3;
	}
	else //Only September and August left
	{
		this->monthKeyValue = 6;
	}
	this->newMonthName = this->month;
	
	if(this->dayOfWeek == "Saturday")
	{
			this->dayNumber = 0;
	}
	else if(this->dayOfWeek == "Sunday")
	{
			this->dayNumber = 1;
	}
	else if(this->dayOfWeek == "Monday")
	{
			this->dayNumber = 2;
	}
	else if(this->dayOfWeek == "Tuesday")
	{
			this->dayNumber = 3;
	}
	else if(this->dayOfWeek == "Wednesday")
	{
			this->dayNumber = 4;
	}
	else if(this->dayOfWeek == "Thursday")
	{
			this->dayNumber = 5;
	}
	else if(this->dayOfWeek == "Friday")
	{
			this->dayNumber = 6;
	}
	
	this->newDayOfWeek = this->dayOfWeek;
	
	if(this->year >= 2000)
	{
		this->JulianOffset = -2;
		this->GregorianOffset = 6;
	}
	else if(this->year >= 1900)
	{
		this->JulianOffset = -1;
		this->GregorianOffset = 0;
	}
	else if(this->year >= 1800)
	{
		this->JulianOffset = 0;
		this->GregorianOffset = 2;
	}
	else if(this->year >= 1700)
	{
		this->JulianOffset = 1;
		this->GregorianOffset = 4;
	}
	else //Only the 1600's left in our given range
	{
		this->JulianOffset = 2;
		this->GregorianOffset = 6;
	}
	
	if((this->year % 4 == 0 && this->year % 100 != 0)
			||this->year %400 == 0)
	{
		this->isLeapYear = true;
	}
	else this->isLeapYear = false;
}

void Date::testStyle()
{
	int test (0);
	
	test = (twoDigitYear/4)+day;
	test += monthKeyValue;
	if(isLeapYear)
	{
		if(month == "January" || month == "February")
		{
			test--;
		}
	}
	test += JulianOffset;
	
	test += twoDigitYear;
	
	test = test%7;
	
	if(test == dayNumber)
	{
		isJulian = true;
	}
	else
	{
		test = (twoDigitYear/4)+day;
		test += monthKeyValue;
		if(isLeapYear)
		{
			if(month == "January" || month == "February")
			{
				test--;
			}
		}
		test += GregorianOffset;
		
		test += twoDigitYear;
		
		test = test%7;
		if(test == dayNumber)
		{
			isJulian = false;
		}
		else
		{
			exit(1);
		}
	}
}
	
void Date::Convert()
{
	int monthNumber (0);
	//Find month number
	if(this->month == "January")
	{
		monthNumber = 1;
	}
	else if(this->month == "February")
	{
			monthNumber = 2;
	}
	else if(this->month == "March")
	{
			monthNumber = 3;
	}
	else if(this->month == "April")
	{
			monthNumber = 4;
	}
	else if(this->month == "May")
	{
			monthNumber = 5;
	}
	else if(this->month == "June")
	{
			monthNumber = 6;
	}
	else if(this->month == "July")
	{
			monthNumber = 7;
	}
	else if(this->month == "August")
	{
			monthNumber = 8;
	}
	else if(this->month == "September")
	{
			monthNumber = 9;
	}
	else if(this->month == "October")
	{
			monthNumber = 10;
	}
	else if(this->month == "November")
	{
			monthNumber = 11;
	}
	else if(this->month == "December")
	{
			monthNumber = 12;
	}

	//Find Julian Day
	double jd (0);
	
	int a = ((14-monthNumber)/12 );
	double y = floor( (year+4800) -a );
	double m = floor( (monthNumber+(12*a))-3 );
	
	
	
	if(isJulian)
	{
		jd = day + floor( (153*m+2)/5 ) + 365*y + floor(y/4) - 32083;
		
		float x = jd - 1721118.5;
		x = floor(x);
		y = jd - 1721118.5 - x;
		float z = 100*x - 25;
		a = static_cast<int>(floor(z/3652425));
		double b = a-floor(a/4);
		double Year = floor( (100*b + z)/36525 );
		float c = b + x-365*Year-floor(year/4);
		double temp;
		modf( (( 5 * c + 456 )/153 ), &temp );
		newMonth = static_cast<int>( temp );
		double tmp;
		modf( ( 153 * newMonth - 457) / 5, &tmp );
		
		newDay = static_cast<int>( c - tmp + y );		
		if(newMonth > 12)
		{
			Year++;
			newMonth -= 12;
		}
		newYear = static_cast<int>( Year );
		
	}
	else
	{
		jd = day + floor( (153*m+2)/5 ) + 365*y + floor(y/4) - floor(y / 100) + floor
		( y / 400) - 32045;
		
		double x = jd - 1721116.5;
		x = floor(x);
		y = jd - 1721116.5 -x;
		double Year = floor((100*x -25)/36525);
		double z = x-(365*Year)-floor(Year/4);
		double temp;
		modf(((5*z+456)/153 ), &temp);
		newMonth = static_cast<int>( temp );
		double tmp;
		modf(((153*newMonth-457)/5), &tmp );
		newDay = static_cast<int>( z - tmp +y );
		if(newMonth > 12)
		{
			Year++;
			newMonth-=12;
		}
	
		newYear = static_cast<int>( Year );	
		
	}
	
	//Convert back to the corresponding string
	switch(newMonth)
	{
		case 1:
			this->newMonthName = "January";
			break;
		case 2:
			this->newMonthName = "February";
			break;
		case 3:
			this->newMonthName = "March";
			break;
		case 4:
			this->newMonthName = "April";
			break;
		case 5:
			this->newMonthName = "May";
			break;
		case 6:
			this->newMonthName = "June";
			break;
		case 7:
			this->newMonthName = "July";
			break;
		case 8:
			this->newMonthName = "August";
			break;
		case 9:
			this->newMonthName = "September";
			break;
		case 10:
			this->newMonthName = "October";
			break;
		case 11:
			this->newMonthName = "November";
			break;
		case 12:
			this->newMonthName = "December";
			break;	
	}
}
Thanks in advance!

Post Reply

Return to “Volume 1 (100-199)”