Advertisement
anechka_ne_plach

Untitled

Apr 13th, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. 1 │ #include <stdio.h>
  2. 2 │ #include <time.h>
  3. 3 │ #include <stdint.h>
  4. 4 │ #include <limits.h>
  5. 5 │
  6. 6 │ enum { DATE_SIZE = 20 };
  7. 7 │
  8. 8 │ int main() {
  9. 9 │ time_t rawtime, today;
  10. 10 │ struct tm *info;
  11. 11 │ time(&today);
  12. 12 │
  13. 13 │ int64_t delta;
  14. 14 │ while (scanf("%lld", &delta) != EOF) {
  15. 15 │ int64_t tmp = delta * 24 * 60 * 60;
  16. 16 │ if (tmp < INT32_MIN || tmp > INT32_MAX) {
  17. 17 │ printf("OVERFLOW\n");
  18. 18 │ continue;
  19. 19 │ }
  20. 20 │ tmp += today;
  21. 21 │ if (tmp < INT32_MIN || tmp > INT32_MAX) {
  22. 22 │ printf("OVERFLOW\n");
  23. 23 │ continue;
  24. 24 │ }
  25. 25 │
  26. 26 │ rawtime = tmp;
  27. 27 │ info = localtime(&rawtime);
  28. 28 │ char buf[DATE_SIZE];
  29. 29 │ strftime(buf, DATE_SIZE, "%Y-%m-%d", info);
  30. 30 │ printf("%s\n", buf);
  31. 31 │ }
  32. 32 │ }
  33.  
  34. 1 │ #include <stdio.h>
  35. 2 │ #include <time.h>
  36. 3 │ #include <stdint.h>
  37. 4 │ #include <limits.h>
  38. 5 │ #include <stdlib.h>
  39. 6 │ #include <sys/types.h>
  40. 7 │ #include <sys/stat.h>
  41. 8 │ #include <fcntl.h>
  42. 9 │ #include <unistd.h>
  43. 10 │
  44. 11 │ int main() {
  45. 12 │ struct tm *info = malloc(sizeof(struct tm));
  46. 13 │
  47. 14 │ FILE* ptr = fopen("input.txt", "r");
  48. 15 │ if (ptr == NULL) {
  49. 16 │ exit(1);
  50. 17 │ }
  51. 18 │
  52. 19 │ int year, month, day, hour, min, sec;
  53. 20 │ int first_time = 1;
  54. 21 │ int64_t last_time;
  55. 22 │ while (fscanf(ptr, "%d/%02d/%02d%02d:%02d:%02d", &year, &month, &day, &hour, &min, &sec) != EOF) {
  56. 23 │ info->tm_year = year - 1900;
  57. 24 │ info->tm_mon = month - 1;
  58. 25 │ info->tm_mday = day;
  59. 26 │ info->tm_hour = hour;
  60. 27 │ info->tm_min = min;
  61. 28 │ info->tm_sec = sec;
  62. 29 │ info->tm_isdst = -1;
  63. 30 │ int64_t now = mktime(info);
  64. 31 │ if (!first_time) {
  65. 32 │ printf("%lld\n", now - last_time);
  66. 33 │ } else {
  67. 34 │ first_time = 0;
  68. 35 │ }
  69. 36 │ last_time = now;
  70. 37 │ }
  71. 38 │
  72. 39 │ fclose(ptr);
  73. 40 │ free(info);
  74. 41 │ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement