602 - What Day Is It?

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

Moderator: Board moderators

galgamet
New poster
Posts: 5
Joined: Thu May 09, 2002 9:29 pm

602 - What Day Is It?

Post by galgamet »

Although my program did all the test inputs correctly, I got a WA. Could someone please print test inputs and their corresponding outputs or check my algorithm and tell me what's wrong with it ?
Thanks in advance

[c]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int valid(int d, int m, int y);
char *mname(int month);
char *wday (int d, int m, int y);
int DaysInYear(int year);
int DaysInMonthInYear(int month, int year);
long DaysSinceZ(int day, int month, int year);

int main(void)
{
int day = 1, month = 1, year = 1;

while(1) {
scanf("%d %d %d", &month, &day, &year);
if (!(day && month && year)) break;

if(valid(day, month, year))
printf("%s %i, %i is a %s\n", mname(month), day, year, wday(day, month, year));
else
printf("%i/%i/%i is an invalid date.\n", month, day, year);
}

return 0;
}

int valid(int d, int m, int y)
{
if (m>12) return 0;
if (d>DaysInMonthInYear(m, y)) return 0;

return 1;
}

char *mname(int month)
{
char *c = malloc(10);

switch (month) {
case 1:
strcpy(c, "January");
break;

case 2:
strcpy(c, "February");
break;

case 3:
strcpy(c, "March");
break;

case 4:
strcpy(c, "April");
break;

case 5:
strcpy(c, "May");
break;

case 6:
strcpy(c, "June");
break;

case 7:
strcpy(c, "July");
break;

case 8:
strcpy(c, "August");
break;

case 9:
strcpy(c, "September");
break;

case 10:
strcpy(c, "October");
break;

case 11:
strcpy(c, "November");
break;

case 12:
strcpy(c, "December");
break;
}

return c;
}

char *wday (int d, int m, int y)
{
char *c = malloc(10);
int dd;

dd = ((DaysSinceZ(d, m, y)+1)%7) + 1;

switch (dd) {
case 1:
strcpy(c, "Monday");
break;

case 2:
strcpy(c, "Tuesday");
break;

case 3:
strcpy(c, "Wednesday");
break;

case 4:
strcpy(c, "Thursday");
break;

case 5:
strcpy(c, "Friday");
break;

case 6:
strcpy(c, "Saturday");
break;

case 7:
strcpy(c, "Sunday");
break;
}

return c;
}

int DaysInYear(int year)
{
if ((!(year % 4) && (year % 100)) || !(year % 400))
return 366;
else
return 365;
}

int DaysInMonthInYear(int month, int year)
{
switch(month)
{
case 2:
if ((!(year % 4) && (year % 100)) || !(year % 400))
return 29;
else
return 28;

case 4:
case 6:
case 9:
case 11:
return 30;

case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;

default:
return 0;
}
}

long DaysSinceZ(int day, int month, int year)
{
int n;
long c = 0;

for (n = 0; n < year; n += 1)
c += DaysInYear(n);

for (n = 1; n < month; n += 1)
c += DaysInMonthInYear(n, year);

c += day;

if (year > 1752) c-=11;
if ((year == 1752) && (month > 9)) c-=11;
if ((year == 1752) && (month == 9) && (day > 2)) c-= 11;

return c;
}
[/c][/c]

galgamet
New poster
Posts: 5
Joined: Thu May 09, 2002 9:29 pm

P.S.

Post by galgamet »

P.S. I changed the while break conditions and valid():

while() breaker now reads:
[c]
if (!day && !month && !year) break;
[/c]

here is valid():
[c]
int valid(int d, int m, int y)
{
if (m>12) return 0;
if (d>DaysInMonthInYear(m, y)) return 0;
if ((d<1) || (m<1) || (y<1)) return 0;

return 1;
}
[/c]

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

As I don't know if your dates are in MMDDYYYY or DDMMYYYY, I just treat as MMDDYYYY.

The following is the output:
January 1, 1 is a Saturday
March 1, 2100 is a Monday
March 1, 2101 is a Tuesday
March 1, 2400 is a Wednesday
March 1, 2401 is a Thursday
March 1, 2300 is a Thursday
Hope can help~ :)

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN »

Have you handled the non-existed days?

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

602

Post by Jalal »

[cpp]
I am confused about some input.
can anybody help me.
wt will about negative or 0 input like
(MM-DD-YY)
-10 12 1020
12 0 0
and another thing is
wt will be output in
2 28 1
2 29 1?
plz. help :cry:
:roll: [/cpp]

LittleJohn
Learning poster
Posts: 83
Joined: Wed Feb 27, 2002 2:00 am
Location: Taiwan

Post by LittleJohn »

Code: Select all

-10/12/1020 is an invalid date.
12/0/0 is an invalid date.
February 28, 1 is a Monday
2/29/1 is an invalid date.

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

Thanx!
I got accepted!

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

What about:
case 2: {month="Februay"; break;}
Please read your code first yourself before posting it here.

raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

602: USA system & need test outputs...

Post by raysa »

Hi guys! Is there any of you know what should these inputs result... ??

Code: Select all

1 1 0
1 1 1
3 1 401
3 1 801
2 29 1000
3 1 1000
9 3 1752
9 13 1752
I'm confused with the sentence :
' England and its empire (including the United States) didn't switch to the Gregorian calendar system until 1752, when the day following September 2 was declared to be September 14. '
Do the days September 3rd 1752 until September 13th 1752 ever exist in the USA calendar?

Best regards,
Raysa
Last edited by raysa on Wed Apr 09, 2003 8:50 am, edited 1 time in total.

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Output:

Code: Select all

January 1, 0 is a Thursday
January 1, 1 is a Saturday
March 1, 401 is a Friday
March 1, 801 is a Monday
February 29, 1000 is a Thursday
March 1, 1000 is a Friday
9/3/1752 is an invalid date.
9/13/1752 is an invalid date.
raysa wrote:Do the days September 3rd 1752 until September 13th 1752 ever exist in the USA calendar?
These days aren't exist in US calendar.

raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

Post by raysa »

Ok, I've matched those results upthere. Thank's!
But, unfortunately, I'm still getting WA...

Now, it makes me wonder: what's also the output of:

Code: Select all

2 28 0
2 29 0
If you don't mind, please give me some 'creative' inputs
to match my results with yours as a comparison...

or maybe I can send you my code via e-mail to be tested. My code is
a little bit long <about 200 lines> so I'm affraid it's a bad idea to
patch it here...

Thank's for your attention !!!

Best regards,
Raysa
Last edited by raysa on Wed Apr 09, 2003 8:51 am, edited 1 time in total.

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

OK, more I/O. Input:

Code: Select all

2 28 0
2 29 0
1 1 1
9 10 2500
5 5 999
7 3 8888
2 27 1000
2 28 1000
2 29 1000
2 30 1000
3 1 1000
2 27 1400
2 28 1400
2 29 1400
2 30 1400
3 1 1400
2 27 1800
2 28 1800
2 29 1800
2 30 1800
3 1 1800
2 27 2000
2 28 2000
2 29 2000
2 30 2000
3 1 2000
2 27 2100
2 28 2100
2 29 2100
2 30 2100
3 1 2100
2 27 10000
2 28 10000
2 29 10000
2 30 10000
3 1 10000
10 1 1752
10 2 1752
11 1 1752

0 0 0
Output:

Code: Select all

February 28, 0 is a Saturday
February 29, 0 is a Sunday
January 1, 1 is a Saturday
September 10, 2500 is a Friday
May 5, 999 is a Friday
July 3, 8888 is a Saturday
February 27, 1000 is a Tuesday
February 28, 1000 is a Wednesday
February 29, 1000 is a Thursday
2/30/1000 is an invalid date.
March 1, 1000 is a Friday
February 27, 1400 is a Friday
February 28, 1400 is a Saturday
February 29, 1400 is a Sunday
2/30/1400 is an invalid date.
March 1, 1400 is a Monday
February 27, 1800 is a Thursday
February 28, 1800 is a Friday
2/29/1800 is an invalid date.
2/30/1800 is an invalid date.
March 1, 1800 is a Saturday
February 27, 2000 is a Sunday
February 28, 2000 is a Monday
February 29, 2000 is a Tuesday
2/30/2000 is an invalid date.
March 1, 2000 is a Wednesday
February 27, 2100 is a Saturday
February 28, 2100 is a Sunday
2/29/2100 is an invalid date.
2/30/2100 is an invalid date.
March 1, 2100 is a Monday
February 27, 10000 is a Sunday
February 28, 10000 is a Monday
February 29, 10000 is a Tuesday
2/30/10000 is an invalid date.
March 1, 10000 is a Wednesday
October 1, 1752 is a Sunday
October 2, 1752 is a Monday
November 1, 1752 is a Wednesday
If you still have troubles with your code you can send it to me via "Private Message". I'll try to check what's wrong.

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

602

Post by angga888 »

I have tried so many input using my Pascal program and it works correctly. But I still got WA. Why?
Can anyone answer my question below:
- What is the maximum limit for the year (in the problem, there are only stated the minimum years,that's >=0 ) ? Is the maximum year can be stored in an longint variable ?
- Is year 0 is a leap year ?

And if you don't mind, could you send your exe file of 602 to my e-mail (angga888@indosat.net.id) in order to check input ?

Thanks for helping me.
Regards,
Angga.[/pascal]

raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

Post by raysa »

Thank's a lot, Ivan Golubev !!!

I've got a miscalculation in the year 2000 and 1800 in your test case...
Now, I've got Accepted (AC). You're really a great helper!!!

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

Be confirm no input will be less than 1.
so print invalid input in there :wink:

Post Reply

Return to “Volume 6 (600-699)”