fork download
  1. #include <iostream>
  2.  
  3. bool isLeapYear( const uint16_t year )
  4. {
  5. return ( (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0) );
  6. }
  7.  
  8. uint8_t getDaysInMonth( const uint8_t month, const uint16_t year )
  9. {
  10. if ( month == 2 )
  11. return isLeapYear( year ) ? 29 : 28;
  12.  
  13. else if ( month == 4 || month == 6 || month == 9 || month == 11 )
  14. return 30;
  15.  
  16. return 31;
  17. }
  18.  
  19. uint16_t getDaysInYear( const uint16_t year )
  20. {
  21. return isLeapYear( year ) ? 366 : 365;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27. int startYear = 1998;
  28. int daysOffset = 4003;
  29.  
  30.  
  31. int d = daysOffset+1;
  32. int m = 1;
  33. int y = startYear;
  34.  
  35. while ( d > getDaysInYear( y ) )
  36. d -= getDaysInYear( y++ );
  37.  
  38. while ( d > getDaysInMonth( m, y ) )
  39. d -= getDaysInMonth( m++, y );
  40.  
  41.  
  42. printf( "%d %d %d", d, m, y );
  43.  
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
17 12 2008