Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. enum
  5. {
  6. GREG_YEAR = 1925,
  7. GREG_MON = 10,
  8. GREG_DAY = 7,
  9. START_YEAR = 1900,
  10. SEC_DAY = 24 * 60 * 60,
  11. SEC_MON = SEC_DAY * 30,
  12. SEC_YEAR = SEC_MON * 12
  13. };
  14.  
  15. time_t sec(int year, int mon, int day) {
  16. struct tm ret;
  17. ret.tm_year = year - START_YEAR;
  18. ret.tm_mon = mon - 1;
  19. ret.tm_mday = day;
  20. ret.tm_isdst = 0;
  21. ret.tm_hour = 0;
  22. ret.tm_min = 0;
  23. ret.tm_sec = 0;
  24. return mktime(&ret);
  25. }
  26.  
  27. int main() {
  28. time_t t = time(NULL);
  29. struct tm lt = {0};
  30.  
  31. localtime_r(&t, &lt);
  32.  
  33. int curr_year, curr_mon, curr_day;
  34. time_t start = sec(GREG_YEAR, GREG_MON, GREG_DAY);
  35. while (scanf("%d%d%d", &curr_year, &curr_mon, &curr_day) == 3) {
  36. time_t curr_time = sec(curr_year, curr_mon, curr_day);
  37. long long sub = (long long) curr_time - (long long) start + lt.tm_gmtoff;
  38. long long new_year, new_mon, new_day;
  39. new_year = sub / SEC_YEAR + 1;
  40. sub %= SEC_YEAR;
  41. new_mon = sub / SEC_MON + 1;
  42. sub %= SEC_MON;
  43. new_day = sub / SEC_DAY + 1;
  44. printf("%lld %lld %lld\n", new_year, new_mon, new_day);
  45. }
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement