/***************************************************************************** Copyright (c) British Informatics Olympiad, 2004 BIO 2004 Question 1 "Mayan Calendar" Question by Richard Forster Example solution by Antony Rix. This program may be freely copied by persons or organisations involved in the British Informatics Olympiad or the International Olympiad in Informatics, on condition that no changes are made and this notice is not altered or removed. Distribution for profit is forbidden unless permission is first obtained in writing from the BIO. This program is for educational purposes only and comes with no warranty, implied or otherwise, as to its fitness for any purpose. http://www.olympiad.org.uk/ *****************************************************************************/ #include void main( void ) { long Ndays = 0; int x; int Year = 2000; int Month = 1; int Day = 1; /* Read the Mayan date and compute the number of days since 1 1 2000 */ scanf("%d", &x); Ndays += 20L * 20L * 18L * 20L * (x - 13L); scanf("%d", &x); Ndays += 20L * 18L * 20L * (x - 20L); scanf("%d", &x); Ndays += 18L * 20L * (x - 7L); scanf("%d", &x); Ndays += 20L * (x - 16L); scanf("%d", &x); Ndays += (x - 3L); printf("Number of days since 1 1 2000: %ld\n", Ndays); /* Run through the months to find the date in our calendar */ do { if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* Jan */ if( (Year % 4) == 0 ) { if( Ndays >= 29 ) { Ndays -= 29; Month++; } /* Feb in leap year */ } else { if( Ndays >= 28 ) { Ndays -= 28; Month++; } /* Feb not in leap year */ } if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* Mar */ if( Ndays >= 30 ) { Ndays -= 30; Month++; } /* Apr */ if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* May */ if( Ndays >= 30 ) { Ndays -= 30; Month++; } /* Jun */ if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* Jul */ if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* Aug */ if( Ndays >= 30 ) { Ndays -= 30; Month++; } /* Sept */ if( Ndays >= 31 ) { Ndays -= 31; Month++; } /* Oct */ if( Ndays >= 30 ) { Ndays -= 30; Month++; } /* Nov */ if( Ndays >= 31 ) { Ndays -= 31; Month = 1; Year++; } /* Dec */ } while( Ndays >= 31 ); Day += Ndays; printf("%d %d %d\n", Day, Month, Year); } /* End of program */