Page 2 of 2

Posted: Sat Dec 30, 2006 4:05 pm
by rickyliu
Here are the testing input and the output from my AC program:
Input:

Code: Select all

Saturday 1 January 1600
Tuesday 1 January 1600
Tuesday 29 February 2000
Sunday 12 March 2000
Monday 13 March 2000
Tuesday 14 March 2000
Thursday 31 December 2099
Wednesday 31 December 2099
Saturday 29 August 1992
Saturday 16 August 1992
Wednesday 19 December 1991
Monday 1 January 1900
#
Output:

Code: Select all

Saturday 22* December 1599
Tuesday 11 January 1600
Tuesday 16* February 2000
Sunday 28* February 2000
Monday 29* February 2000
Tuesday 1* March 2000
Thursday 18* December 2099
Wednesday 13 January 2100
Saturday 16* August 1992
Saturday 29 August 1992
Wednesday 1 January 1992
Monday 20* December 1899
Lucas, maybe your have got AC. Anyway, your output in the second line differed with mine. Here is yours:

Code: Select all

Saturday 22* December 1599
Tuesday 10 January 1600       <-- this one differed
Tuesday 16* February 2000
Sunday 28* February 2000
Monday 29* February 2000
Tuesday 1* March 2000
Thursday 18* December 2099
Wednesday 13 January 2100
Saturday 16* August 1992
Saturday 29 August 1992
Wednesday 1 January 1992
Monday 20* December 1899
Hope this helps.

Just be careful

Posted: Mon Dec 10, 2007 6:01 pm
by lantimilan
Just got AC after three days struggle.
This problem takes extreme care, or maybe I am careless.

Check every boundary condition carefully, Feb 29, 1600, 1700, 2000 years, and when count from Dec 1899 to Jan 1900. Basically put some assert will help.

Re: 150 - Double Time

Posted: Fri Jul 28, 2017 4:19 pm
by rafastv
Hi, there, some tips for you:

1) Once you have a code that you think it is working, write a program to generate all possible dates between the range specified and check for negative numbers or zero.

2) Check for leap days, days between months and between years.

3) As said before, the first day in the Julian calendar is Friday 5 October 1582, which corresponds to Friday 15 October 1582 in the Gregorian calendar.

Good luck! This problem is quite fun, don't know why more people won't do it.

Re: 150 - Double Time

Posted: Sun Feb 11, 2018 4:09 am
by metaphysis
Test data generator.

Code: Select all

#include <iostream>

using namespace std;

const string months[12] = { "January", "February", "March", "April", "May",
    "June", "July", "August", "September", "October", "November", "December"
};

const string weekdays[7] = { "Monday", "Tuesday", "Wednesday", "Thursday",
    "Friday", "Saturday", "Sunday"
};

const int daysInMonth[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}
};

int isLeapYear(int year, bool useOldFormat)
{
    return (useOldFormat ? year % 4 == 0 : (year % 400 == 0 || (year % 4 == 0
                && year % 100 != 0))) ? 1 : 0;
}

int main(int argc, char* argv[])
{
    int dayOfWeek = 5;
    for (int i = 1600; i <= 1601; i++)
        for (int j = 0; j < 12; j++)
            for (int k = 1; k <= daysInMonth[isLeapYear(i, false)][j]; k++)
            {
                cout << weekdays[dayOfWeek % 7] << " " << k << " " << months[j] << " " << i << "\n";
                dayOfWeek++;
            }
            
    cout << "#";
    
    return 0;
}