-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate1.cpp
More file actions
26 lines (20 loc) · 708 Bytes
/
Copy pathdate1.cpp
File metadata and controls
26 lines (20 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <time.h>
using namespace std;
int main(int argc, char *argv[]) {
time_t current_timestamp = time(0);
int days;
while (cin >> days) {
time_t timestamp = current_timestamp + days * 60 * 60 * 24;
int overflow_check_int = current_timestamp + days * 60 * 60 * 24;
long long overflow_check_long = (long long)current_timestamp + (long long)days * 60 * 60 * 24;
if (overflow_check_long != overflow_check_int) {
cout << "OVERFLOW\n";
continue;
}
struct tm * timeinfo = localtime(×tamp);
char buf[20];
strftime(buf, 20, "%F", timeinfo);
printf("%s\n", buf);
}
}