SHARE
TWEET

Untitled

a guest Oct 20th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5. #include <stdint.h>
  6.  
  7. enum
  8. {
  9.     BEG_YEAR = 1925,
  10.     BEG_MON = 10,
  11.     BEG_DAY = 7
  12. };
  13.  
  14. int
  15. main()
  16. {  
  17.     struct tm beg_date = {0};
  18.     beg_date.tm_isdst = -1;
  19.     beg_date.tm_year = BEG_YEAR - 1900;
  20.     beg_date.tm_mon = BEG_MON - 1;
  21.     beg_date.tm_mday = BEG_DAY;
  22.     long long  beg_date_comp = mktime(&beg_date);
  23.  
  24.     struct tm now_date = {0};
  25.     now_date.tm_isdst = -1;
  26.  
  27.    
  28.  
  29.     while(scanf("%d %d %d", &now_date.tm_year, &now_date.tm_mon, &now_date.tm_mday) == 3) {
  30.         now_date.tm_year -= 1900;
  31.         now_date.tm_mon -= 1;
  32.         now_date.tm_hour = 12;
  33.  
  34.         long long  now_date_comp = mktime(&now_date);
  35.         if (now_date_comp == -1) {
  36.             return -1;
  37.         }
  38.         long long  hark_date_comp = now_date_comp - beg_date_comp;
  39.  
  40.         int hark_date_comp_indays = hark_date_comp / 60 / 60 / 24;
  41.         int hark_date_year = 1 + hark_date_comp_indays / 12 / 30;
  42.         int hark_date_mon = 1 + hark_date_comp_indays / 30 % 12;
  43.         int hark_date_mday = 1 + hark_date_comp_indays % 30;
  44.  
  45.         printf("%d ", hark_date_year);
  46.         printf("%d ", hark_date_mon);
  47.         printf("%d\n", hark_date_mday);
  48.  
  49.         memset(&now_date, 0, sizeof(now_date));
  50.         now_date.tm_isdst = -1;
  51.     }
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top