893 - Y3K Problem

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

Moderator: Board moderators

893 - Y3K Problem

Postby bsd_lover » Wed May 18, 2005 10:38 am

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 ?
bsd_lover
New poster
 
Posts: 4
Joined: Sun Oct 14, 2001 2:00 am

Postby n00i3 » Wed Sep 21, 2005 10:23 pm

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:
n00i3
New poster
 
Posts: 20
Joined: Thu Sep 15, 2005 8:49 pm

Postby erdos » Mon Apr 03, 2006 2:35 am

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
erdos
New poster
 
Posts: 32
Joined: Sat Jul 06, 2002 9:38 pm
Location: Lisbon

Postby fixit » Sun Jun 11, 2006 12:07 am

I have the same outputs in my program, but W/A :(
I don't know where is the problem :(
Maybe someone give I/O ?
fixit
New poster
 
Posts: 5
Joined: Tue Jun 06, 2006 7:39 pm

Postby Ktototam » Mon Aug 21, 2006 7:45 pm

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!
Ktototam
New poster
 
Posts: 1
Joined: Mon Aug 21, 2006 7:28 pm

Postby sm_hosein » Sun Mar 18, 2007 3:27 pm

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]
sm_hosein
New poster
 
Posts: 3
Joined: Sat Oct 28, 2006 11:39 am

Re:

Postby annhy » Mon Apr 16, 2012 7:45 am

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
annhy
New poster
 
Posts: 40
Joined: Sun May 27, 2007 1:42 am
Location: Taiwan


Return to Volume VIII

Who is online

Users browsing this forum: No registered users and 1 guest