pochti_da

Untitled

Oct 12th, 2020
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/types.h>
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <limits.h>
  7. #include <string.h>
  8. #include <time.h>
  9.  
  10. enum
  11. {
  12.     SECS_IN_DAY = 60 * 60 * 24,
  13.     DAYS_IN_YEAR = 30 * 12,
  14.     DAYS_IN_MONTH = 30
  15. };
  16.  
  17. void
  18. count_date(unsigned long long time)
  19. {
  20.     unsigned long long date = time / SECS_IN_DAY;
  21.     unsigned long long year, month, day;
  22.  
  23.     year = date / DAYS_IN_YEAR;
  24.     date %= DAYS_IN_YEAR;
  25.  
  26.     month = date / DAYS_IN_MONTH;
  27.     date %= DAYS_IN_MONTH;
  28.  
  29.     day = date;
  30.     printf("%lld %lld %lld\n", year + 1, month + 1, day + 1);
  31. }
  32.  
  33. int
  34. main(void)
  35. {
  36.     struct tm st = {.tm_sec = 0, .tm_min = 0, .tm_hour = 0,
  37.                 .tm_mday = 7, .tm_mon = 9, .tm_isdst = -1, .tm_year = 25};
  38.     unsigned long long start = timegm(&st);
  39.  
  40.     unsigned int year, month, day;
  41.     while (scanf("%u%u%u", &year, &month, &day) == 3) {
  42.         struct tm tm = {.tm_sec = 0, .tm_min = 0, .tm_hour = 0,
  43.                 .tm_mday = day, .tm_mon = month - 1, .tm_isdst = -1, .tm_year = year - 1900};
  44.         unsigned long long time = timegm(&tm);
  45.         count_date(time - start);
  46.     }
  47.  
  48.     return 0;
  49. }
  50.  
RAW Paste Data