Advertisement
MonsterScripter

CodinGame_2023_08_22__15_38_19__minutes.c

Aug 22nd, 2023
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdbool.h>
  3.  
  4. /**
  5.     Entrée
  6.     8:12
  7.     14:32
  8.  
  9.     Sortie attendue
  10.     380
  11.  
  12.  **/
  13.  
  14. long chars_to_int(const char *s);
  15.  
  16. int main()
  17. {
  18.     char depart[6];
  19.     scanf("%[^\n]", depart); fgetc(stdin);
  20.     char arrive[6];
  21.     scanf("%[^\n]", arrive);
  22.  
  23.     // Write an answer using printf(). DON'T FORGET THE TRAILING \n
  24.     // To debug: fprintf(stderr, "Debug messages...\n");
  25.     char *ptr = strtok(arrive, ":");
  26.     long hourArr = chars_to_int(ptr);
  27.     ptr = strtok(NULL, ":");
  28.     long minArr = chars_to_int(ptr);
  29.  
  30.     ptr = strtok(depart, ":");
  31.     long hourDep = chars_to_int(ptr);
  32.     ptr = strtok(NULL, ":");
  33.     long minDep = chars_to_int(ptr);
  34.  
  35.     long sum = ((hourArr-hourDep) * 60) + (minArr - minDep);
  36.     printf("%ld", sum);
  37.  
  38.     return 0;
  39. }
  40.  
  41. long chars_to_int(const char *s) {
  42.     char *endptr;
  43.     long num = strtol(s, &endptr, 10);
  44.     if (*endptr == '\0') {
  45.         return num;
  46.     } else {
  47.         exit(-1);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement