Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #define _XOPEN_SOURCE
  2.  
  3. #include <stdlib.h>
  4. #include <sys/stat.h>
  5. #include <stdio.h>
  6. #include <dirent.h>
  7. #include <time.h>
  8. #include <string.h>
  9.  
  10. int main(int argc, char *argv []) {
  11.     const int BUFF_SIZE = 18;
  12.     char first_datetime[BUFF_SIZE];
  13.     char second_datetime[BUFF_SIZE];
  14.     fgets(first_datetime, BUFF_SIZE, stdin);
  15.     struct tm first;
  16.     memset(&first, 0, sizeof(first));
  17.     strptime(first_datetime, "%Y-%m-%d %H:%M", &first);
  18.     first.tm_isdst = -1;
  19.     while(fgets(second_datetime, BUFF_SIZE, stdin) != NULL) {
  20.         time_t first_time = mktime(&first);
  21.         struct tm second;
  22.         memset(&second, 0, sizeof(second));
  23.         strptime(second_datetime, "%Y-%m-%d %H:%M", &second);
  24.         second.tm_isdst = -1;
  25.         time_t second_time = mktime(&second);
  26.         double diff = difftime(second_time, first_time) / 60;
  27.         printf("%ld\n", (long)diff);
  28.         first = second;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement