893 - Y3K Problem

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

Moderator: Board moderators

Post Reply
bsd_lover
New poster
Posts: 4
Joined: Sun Oct 14, 2001 2:00 am

893 - Y3K Problem

Post by bsd_lover »

Hi I am trying to use the Java Calendar / GregorianCalendar utility to compute a future date. The following results are produced by my program.
Input :
1 31 12 2999
40 1 2 2004
60 31 12 1999
60 31 12 2999
146097 31 12 1999
999999 1 1 2000
999999999 31 12 2999
365 28 2 2001
365 28 2 2000
730 28 2 1999
1 28 2 1999
0 0 0 0

output:
1 1 3000
12 3 2004
29 2 2000
1 3 3000
31 12 2399
27 11 4737
2 1 2740907
28 2 2002
27 2 2001
27 2 2001
1 3 1999

I keep on getting wrong answer however. Can anyone think of a case where I am going wrong ?
n00i3
New poster
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm
Contact:

Post by n00i3 »

hey I got the same answers as you i did

I used C++ but im getting wrong answer too :oops: :oops: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:
erdos
New poster
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon
Contact:

Post by erdos »

My program also gives the same answers for those inputs.
(I implemented all the logic myself in C++ efficiently).

Could someone please some tricky inputs and outputs?

Regards,


Jos
fixit
New poster
Posts: 5
Joined: Tue Jun 06, 2006 7:39 pm

Post by fixit »

I have the same outputs in my program, but W/A :(
I don't know where is the problem :(
Maybe someone give I/O ?
Ktototam
New poster
Posts: 1
Joined: Mon Aug 21, 2006 7:28 pm

Post by Ktototam »

Try this test:
Input :
366 1 6 2004
366 1 12 2003
0 0 0 0

Output:
2 6 2005
1 12 2004

You should check not only this year, leap he or no, but also following.
My mistake was in this. Good luck!
sm_hosein
New poster
Posts: 3
Joined: Sat Oct 28, 2006 11:39 am
Contact:

Post by sm_hosein »

I am trying to solve this problem in C++ many times, but I got WA. Can anyone say the problem of my code or some Testcases which help me, please?
Here is my code:

Code: Select all

#include <iostream>

using namespace std;

long long month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main ()
{
	long long year = 0, i, p, d, m, y, kabiseh = 0, kk, lp;
	long long day400year = 365 * 400 + 100 - 4 + 1;
	long long day100year = 365 * 100 + 25 - 1;
	long long day4year = 365 * 4 + 1;
	while ( cin >> p >> d >> m >> y, p != 0 || d != 0 || m != 0 || y != 0 )
	{
		p += ((y - 1) / 400) *  day400year;
		kk = ( ( y - 1 ) % 400 );
		lp = p;
		p += ( kk / 100 ) * day100year;
		kk %= 100;
		p += ( kk / 4 ) * day4year;
		kk %= 4;
		p += kk * 365;
		for ( i = 0; i < m - 1; i++ )
			if ( i == 1 && y % 4 == 0 && ( y % 100 != 0 || y % 400 == 0 ))
				p += 29;
			else
				p += month[i];
		m = 1;
		y = 1;
		p += d - 1;
		d = 1;
		y += ( p / day400year ) * 400;
		p %= day400year;
		y += ( p / day100year ) * 100;
		p %= day100year;
		y += ( p / day4year ) * 4;
		p %= day4year;
		y += p / 365;
		p %= 365;
		p++;
		i = 0;
		while ( p > month[i] &&
			!( i == 1 && ( y % 4 == 0 && ( y % 100 != 0 || y % 400 == 0 )) && p <= 29) )
		{
			if ( i == 1 && y % 4 == 0 && ( y % 100 != 0 || y % 400 == 0 ))
				p -= 29;
			else
				p -= month[i];
			i++;
		}
		m = i + 1;
		d = p;
		cout << d << " " << m << " " << y << endl;
	}
	return 0;
}
[/code]
annhy
New poster
Posts: 40
Joined: Sun May 27, 2007 1:42 am
Location: Taiwan

Re:

Post by annhy »

fixit wrote:I have the same outputs in my program, but W/A :(
I don't know where is the problem :(
Maybe someone give I/O ?
I think there are invalid dates, try this:

Code: Select all

1 31 2 2012
365 31 2 2012
0 0 0 0
x2000
New poster
Posts: 1
Joined: Mon Nov 18, 2013 4:00 am

Re: 893 - Y3K Problem

Post by x2000 »

if we are inputting dates below, what should be the output line?
1 31 2 2012
365 31 2 2012
0 0 0 0

there are need to printf like this?
printf("you must input the proper dates"); LOL
:lol:
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 893 - Y3K Problem

Post by brianfry713 »

There are no invalid dates in the judge's input.
Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 893 - Y3K Problem

Post by uDebug »

The sample input on this problem got me thinking in the right direction.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
musfiqur.cse
New poster
Posts: 10
Joined: Tue Dec 03, 2013 8:48 pm

893- Y3K

Post by musfiqur.cse »

I don't know why I'm getting wa!

Code: Select all

#include<bits/stdc++.h>
using namespace std;
long long p[1000];
int main()

{

    long long int rd,dd,mm,yy;
    p[1]=31;p[3]=31;p[5]=31;p[7]=31;p[8]=31;p[10]=31;p[12]=31;p[2]=28;
    p[4]=30;p[6]=30;p[9]=30;p[11]=30;
    while(cin>>rd>>dd>>mm>>yy)
    {
        if(rd==0&&dd==0&&mm==0&&yy==0 )
            break;
        if((yy%400==0)||((yy%4==0)&&(yy%100!=0)))
           p[2]=29;
           rd+=dd;
           while(rd>0)
        {
            //cout<<" Check"<<rd<<"\t"<<mm<<"\t"<<yy<<endl;
            rd-=p[mm];
        //cout<<rd<<endl;
            if(mm<=12)
            {
                mm++;
            }
            if(mm>12)
            {
                mm=1;
                yy++;
               if((yy%400==0)||((yy%4==0)&&(yy%100!=0)))
           p[2]=29;
           else
            p[2]=28;
            }

           if(rd<=p[mm])
            break;
        }
       cout<<rd<<" "<<mm<<" "<<yy<<endl;
    }


return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 893- Y3K

Post by brianfry713 »

Input:

Code: Select all

934883506 20 3 2477
931977712 26 10 2063
382035070 17 7 2686
513994357 17 12 2583
25263981 11 4 2574
102172969 6 10 2694
76503508 8 1 2970
118437952 20 6 2061
677284329 11 7 2651
221377439 10 5 2133
186935713 14 10 2248
140911081 19 10 2498
636192756 19 1 2460
631047599 3 8 2043
884528666 28 10 2075
435277482 3 3 2264
732099539 12 6 2118
603326795 27 9 2553
301191290 22 9 2855
622418286 4 12 2717
401817541 7 6 2718
42746448 14 5 2038
302191172 3 5 2984
137454847 7 10 2357
913893311 20 6 2610
724559443 15 2 2351
861933603 18 4 2703
192683279 10 9 2955
544042725 25 8 2023
559589086 26 2 2148
883258385 3 1 2026
398450295 25 6 2365
431199104 11 8 2072
913350654 4 9 2139
755852339 2 9 2688
693107385 27 11 2164
972735002 15 7 2256
358315426 5 1 2450
897407705 28 3 2358
705214398 1 12 2701
391017168 7 7 2807
99975166 7 6 2178
943174529 22 1 2771
572083528 27 4 2378
337932778 7 5 2062
150472992 9 11 2540
137247392 18 8 2989
25310889 27 10 2814
62352790 6 1 2143
564859486 21 1 2241
664799706 16 7 2380
137532611 12 2 2013
682733726 18 2 2434
707771221 16 6 2760
424742779 2 5 2418
144380881 1 1 2804
610050206 4 7 2550
502523678 17 9 2254
324833787 25 1 2654
370171111 16 4 2063
569916289 27 1 2223
334179102 27 2 2904
107123199 22 8 2829
1705744 18 11 2039
72500290 23 9 2306
624581878 5 3 2806
969516156 11 9 2180
300076821 24 6 2632
426773699 7 2 2195
161000748 19 1 2550
753220439 28 8 2963
771821973 12 1 2355
362714217 12 10 2683
885538886 25 8 2405
275862020 27 11 2756
813205792 6 6 2683
981136189 1 12 2273
684130130 22 7 2637
922304379 26 2 2347
317820102 17 9 2299
269855717 5 1 2921
939619247 24 1 2995
363101413 4 6 2228
612657185 18 1 2294
651095446 4 6 2207
758156785 26 5 2393
43694575 9 11 2303
933877192 6 5 2497
690961796 6 10 2626
871970647 4 1 2209
99932632 13 8 2121
399997999 10 7 2635
359983067 14 1 2387
8635518 1 3 2961
91362532 14 1 2927
906355481 13 4 2752
575838590 14 3 2992
630324472 26 1 2468
941639275 25 3 2371
184508287 3 6 2864
AC output:

Code: Select all

27 4 2562101
16 2 2553732
14 1 1048663
17 9 1409852
15 9 71744
7 11 282434
6 7 212429
27 7 326333
12 1 1856993
13 3 608244
20 5 514061
28 3 388300
27 8 1744296
25 3 1729793
21 1 2423833
9 6 1194013
26 11 2006538
26 5 1654406
20 6 827489
23 4 1706841
28 6 1102857
2 3 119074
1 9 830355
9 5 378696
14 5 2504765
2 7 1986127
5 5 2362597
4 8 530504
14 1 1491562
13 1 1534251
1 5 2420305
2 5 1093285
30 8 1182655
30 10 2502808
1 2 2072142
22 6 1899828
8 7 2665514
30 4 983484
29 1 2459377
11 5 1933513
27 2 1073376
21 2 275901
18 3 2585095
26 10 1568689
13 11 927290
1 12 414521
24 3 378760
6 9 72113
26 2 172859
20 10 1548773
24 4 1822540
13 8 378564
2 8 1871695
29 3 1940572
25 7 1165324
5 6 398105
29 3 1672811
23 10 1378117
8 10 892018
15 5 1015557
15 11 1562600
18 6 917855
31 12 296122
19 1 6710
11 10 200805
10 4 1712853
10 10 2656625
29 11 824214
21 10 1170661
16 2 443355
5 3 2065211
27 10 2115531
29 7 995761
8 10 2426928
18 6 758041
7 4 2229165
25 7 2688533
26 3 1875722
11 10 2527530
5 8 872461
14 11 741760
9 3 2575585
30 4 996366
12 6 1679692
16 3 1784846
4 3 2078156
16 7 121935
3 4 2559366
27 11 1894415
22 7 2389583
14 11 275727
4 11 1097792
14 3 987987
30 5 26604
25 2 253069
21 4 2484269
17 9 1579584
10 11 1728237
30 12 2580491
15 12 508030
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 8 (800-899)”