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

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

Post by Jalal »

9/3/1752 is an invalid date.
9/4/1752 is an invalid date.
9/5/1752 is an invalid date.
9/12/1752 is an invalid date.
Hope can help

dont take any input less 1 as a valid input
:wink:
Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

I have send the exe to ur mail add.
cheak ur outputs
it cant be possible to write 0 month , or 0 day or 0 year :wink: :lol:
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Thanx, Jalal :) I've received your exe file. Now, I'm gonna check my program. :wink:

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

Post by angga888 »

Ok finally, I got Accepted on 602 problem :D . After I got your exe file, I just tried to test many inputs to your exe and compare the output to my program. Finally, I found that I've made miscalculation in deciding whether a year is a leap year or not before and after 1952.
By the way, thank you very much for your help. :D

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

Post by angga888 »

Ok finally, I got Accepted on 602 problem :D . After I got your exe file, I just tried to test many inputs to your exe and compare the output to my program. Finally, I found that I've made miscalculation in deciding whether a year is a leap year or not before and after 1752.
By the way, thank you very much for your help. :D

Regards
Angga
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

sorry to interrupt here
but I think "2 28 0"
is invalid date because the input are positive integers right??

I passed all the test case above, well, except for the first two
,even when I remove my date check condition, but the answer
from the first two cases up there doesn't match with mine

I've send the problem to the judge but I still don't know the
result yet due to the judge error right now.
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

ok, I got AC
apparently "2 28 0" is not on the judge's test case
Last edited by deddy one on Fri Mar 26, 2004 6:49 am, edited 1 time in total.
TWEmp
New poster
Posts: 7
Joined: Tue Jan 21, 2003 4:52 am
Location: Hong Kong
Contact:

Sorry...

Post by TWEmp »

Ivan Golubev wrote: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.
Sorry for interupption, but doesn't year 0 not exist? :o

(I get Wrong answer in 602 either)
raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

Post by raysa »

I think you may assume that there's no year 0 in the Judge's input,
since the year is always in positive numbers...
Well, I hope the following will help:
  • 1/ AFTER September 13th 1752, there is cyclical pattern of date,
    that is: any year that is a multiple of 400 would have its
    first day fall on Saturday <"Math Magic", Scott Flansburg,
    1993>.
    Thus: January 1, 2000 is a Saturday
    January 1, 2400 is a Saturday
    January 1, 8400 is a Saturday
    So, every 400 years the same date is repeated:
    January 7, 1999 is a Thursday
    January 7, 5999 is a Thursday
    2/ Pay more attention to 28/29 Feb & 1 Mar, 31 Dec & 1 Jan when
    examining your code. Are those days related directly?
And, deddy one:

*********** Message was cut ***********

[due to a serious misunderstanding,
I apologize to my very friend, Deddy One,
for any words and insultings...
To everyone who's d-load or read this message
previously, forget all my sayings, coz
it's purely a failure of mine, and I regret it.]


Best regards,


raysa
Last edited by raysa on Wed Oct 08, 2003 5:20 pm, edited 1 time in total.
pywong
New poster
Posts: 1
Joined: Mon Jan 27, 2003 6:39 pm

602

Post by pywong »

what's wrong there? i can't see the bug :o

Code: Select all

#include<stdio.h>
#include<stdlib.h>


int main(void)
{
int day,month,year,yearsbetween,weekday,daysbetween;
int flag=1;

while(flag){
scanf("%d %d %d",&month,&day,&year);

if(!month && !day && !year)
flag=0;

else if(year <= 0 || day > 31 || day <= 0 || month > 12 || month <= 0)
printf("%d/%d/%d is an invalid date.\n",month,day,year);

else if(month == 4 || month == 6 || month == 9 || month == 11)
if (day >= 31)
printf("%d/%d/%d is an invalid date.\n",month,day,year);

else if(((year > 1752 && month == 2 && (year % 4 != 0 || (year % 400 != 0 && year % 100 == 0))) 
|| (year <= 1752 && year%4!=0 && month == 2)) && day > 28)
printf("%d/%d/%d is an invalid date.\n",month,day,year);

else if((year > 1752 && month==2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
|| (year <= 1752 && year%4 == 0 && month == 2))&& day > 29)
printf("%d/%d/%d is an invalid date.\n",month,day,year);

else{
daysbetween = 0;
yearsbetween = year-1;

if(year > 1752 || (year ==1752 && month > 9 ) || (year == 1752 && month == 9 && day >= 14))
daysbetween = yearsbetween * 365 + yearsbetween / 4 - (yearsbetween / 100 - yearsbetween / 400);

else 
daysbetween = yearsbetween * 365 + yearsbetween / 4;

if(month <= 2)
daysbetween += (month-1)*31+day-1;

else if((year>1752 && ((year%4 == 0 && year%100!=0) || year%400==0))
|| year <=1752 && (year%4 == 0)){
if(month<=7){
if((month-1)%2==0)
daysbetween += (month-1)*30+(month-3)/2+day-1;
else
daysbetween += (month-1)*30+month/2-1+day-1;
}
else
daysbetween += 212+(month-8)*30+(month-7)/2+day;
}
else if((year>1752 && (year%4 != 0 || (year%100 == 0 && year%400 != 0)))
   || (year%4 != 0 && year<=1752)) {
if(month<=7){
if((month-1)%2==0)
daysbetween += (month-1)*30+(month-3)/2+day-2;
else
daysbetween += (month-1)*30+month/2-2+day-1;
}
else
daysbetween += 212+(month-8)*30+(month-7)/2+day-1;
}



switch(month){
case 1:
printf("January %d, %d is a ",day,year);
break;
case 2:
printf("February %d, %d is a ",day,year);
break;
case 3:
printf("March %d, %d is a ",day,year);
break;
case 4:
printf("April %d, %d is a ",day,year);
break;
case 5:
printf("May %d, %d is a ",day,year);
break;
case 6:
printf("June %d, %d is a ",day,year);
break; 
case 7:
printf("July %d, %d is a ",day,year);
break;
case 8:
printf("August %d, %d is a ",day,year);
break; 
case 9:
printf("September %d, %d is a ",day,year);
break;
case 10:
printf("October %d, %d is a ",day,year);
break; 
case 11:
printf("November %d, %d is a ",day,year);
break;
case 12:
printf("December %d, %d is a ",day,year);
break;
}


weekday=0;
if(year > 1752 || (year ==1752 && month > 9 ) || (year == 1752 && month == 9 && day >= 14))
weekday = daysbetween%7;

else 
weekday = (daysbetween + 5) % 7;

switch(weekday){
case 1:
printf("Tuesday\n");
break;
case 2:
printf("Wednesday\n");
break;
case 3:
printf("Thursday\n");
break;
case 4:
printf("Friday\n");
break;
case 5:
printf("Saturday\n");
break;
case 6:
printf("Sunday\n");
break;

case 0:
printf("Monday\n");
break;
}

}
}
return 0;
}
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

--CUT--
Last edited by deddy one on Fri Mar 26, 2004 6:46 am, edited 1 time in total.
raysa
New poster
Posts: 40
Joined: Wed Dec 18, 2002 4:23 pm
Location: Indonesia

Post by raysa »

*********** Message was cut ***********
Last edited by raysa on Wed Oct 08, 2003 5:22 pm, edited 1 time in total.
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I have one small question to raysa and deddy one :

Could you our private discussion posts exchange with private messages ? It's not place for this ....

Best regards
Dominik Michniewski
beeplove
New poster
Posts: 17
Joined: Tue Sep 30, 2003 9:28 pm
Location: Boston, MA, USA
Contact:

602

Post by beeplove »

Hello guys,

How did you get the reference of weekday?
I didn't see any reference of the name of weekday in the problem.
To get the name of the day, we should have a weekday name for a certain date.
Do we have it in problem 602?



best regards,
beeplove
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

start with 1 1 1 being as Saturday.
that's my reference when solving this problem.

beware of the day after september 2 1752.
Post Reply

Return to “Volume 6 (600-699)”