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