Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <string>
- using namespace std;
- int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- int main () {
- time_t now;
- struct tm dt1;
- struct tm dt2;
- time(&now);
- dt1 = *localtime(&now);
- dt2 = *localtime(&now);
- string s1, s2;
- cin >> s1 >> s2;
- int m1 = 0, d1 = 0, y1 = 0;
- int m2 = 0, d2 = 0, y2 = 0;
- int k = 1;
- int cc = 0;
- for (int i = s1.length() -1; i >= 0; i--) {
- char c = s1[i];
- if (c ==':') {
- k = 1;
- cc++;
- continue;
- } else if (cc == 0) {
- d1 += (k * int(c - '0'));
- k *= 10;
- } else if (cc == 1) {
- m1 += (k * int(c - '0'));
- k *= 10;
- } else if (cc == 2) {
- y1 += (k * int(c - '0'));
- k *= 10;
- }
- }
- k = 1;
- cc = 0;
- for (int i = s2.length() -1; i >= 0; i--) {
- char c = s2[i];
- if (c ==':') {
- k = 1;
- cc++;
- continue;
- } else if (cc == 0) {
- d2 += (k * int(c - '0'));
- k *= 10;
- } else if (cc == 1) {
- m2 += (k * int(c - '0'));
- k *= 10;
- } else if (cc == 2) {
- y2 += (k * int(c - '0'));
- k *= 10;
- }
- }
- dt1.tm_hour = 0; dt1.tm_min = 0; dt1.tm_sec = 0;
- dt1.tm_mday = d1, dt1.tm_mon = m1, dt1.tm_year = y1;
- dt2.tm_hour = 0; dt2.tm_min = 0; dt2.tm_sec = 0;
- dt2.tm_mday = d2, dt2.tm_mon = m2, dt2.tm_year = y2;
- double s = difftime(mktime(&dt1), mktime(&dt2));
- cout << s / 86400;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment