Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <stack>
- using namespace std;
- pair<int, int> dec(pair<int, int> a, pair<int, int> b) {
- if (a.second < b.second) {
- a.second += 60;
- a.first--;
- }
- return { a.first - b.first, a.second - b.second };
- }
- pair<int, int> r(string a, string b) {
- pair<int, int> d1 = { (a[1] - '0') * 10 + (a[2] - '0'), (a[3] - '0') * 10 + (a[4] - '0') };
- pair<int, int> d2 = { (b[1] - '0') * 10 + (b[2] - '0'), (b[3] - '0') * 10 + (b[4] - '0') };
- if (a[0] != b[0]) {
- if (a[0] == '-') {
- return { d1.first + d2.first + (d1.second + d2.second) / 60, (d1.second + d2.second) % 60 };
- }
- return { -(d1.first + d2.first) + (d1.second + d2.second) / 60, (d1.second + d2.second) % 60 };
- }
- if (a[0] == '-') {
- if (d1 > d2) {
- return dec(d1, d2);
- }
- auto v = dec(d2, d1);
- v.first *= -1;
- return v;
- }
- if (d1 < d2) {
- return dec(d2, d1);
- }
- auto v = dec(d1, d2);
- v.first *= -1;
- return v;
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- map<string, int> month;
- month["Jan"] = 1;
- month["Feb"] = 2;
- month["Mar"] = 3;
- month["Apr"] = 4;
- month["May"] = 5;
- month["Jun"] = 6;
- month["Jul"] = 7;
- month["Aug"] = 8;
- month["Sep"] = 9;
- month["Oct"] = 10;
- month["Nov"] = 11;
- month["Dec"] = 12;
- vector<int> kd = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- vector<string> mnth = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
- string t;
- getline(cin, t);
- string ip, q, name, d, p, extra;
- while (cin >> ip) {
- cin >> q >> name;
- cin >> d;
- d.erase(d.begin());
- cin >> p;
- p.erase(p.begin() + 5);
- getline(cin, extra);
- auto v = r(p, t);
- if (v.first < 0) {
- v.second *= -1;
- }
- int dd = (d[0] - '0') * 10 + (d[1] - '0');
- string M = " ";
- M[0] = d[3];
- M[1] = d[4];
- M[2] = d[5];
- int mm = month[M];
- int yy = (d[7] - '0') * 1000 + (d[8] - '0') * 100 + (d[9] - '0') * 10 + (d[10] - '0');
- int hh = (d[12] - '0') * 10 + (d[13] - '0');
- int mn = (d[15] - '0') * 10 + (d[16] - '0');
- int ss = (d[18] - '0') * 10 + (d[19] - '0');
- if (yy % 4 == 0) {
- kd[2]++;
- }
- mn += v.second;
- if (mn > 59) {
- hh++;
- mn = mn % 60;
- }
- else
- if (mn < 0) {
- mn += 60;
- hh--;
- }
- hh += v.first;
- if (hh > 23) {
- dd++;
- hh %= 24;
- }
- else {
- if (hh < 0) {
- hh += 24;
- dd--;
- }
- }
- if (dd > kd[mm]) {
- mm++;
- dd = 1;
- if (mm == 13) {
- yy++;
- mm = 1;
- }
- }
- if (dd == 0) {
- if (mm == 1) {
- yy--;
- mm = 12;
- dd = 31;
- }
- else {
- mm--;
- dd = kd[mm];
- }
- }
- d = "";
- d += (char)(dd / 10 + '0');
- d += (char)(dd % 10 + '0');
- d += "/" + mnth[mm] + "/";
- string date1 = ":";
- date1 += (char)(hh / 10 + '0');
- date1 += (char)(hh % 10 + '0');
- date1 += ':';
- date1 += (char)(mn / 10 + '0');
- date1 += (char)(mn % 10 + '0');
- date1 += ':';
- date1 += (char)(ss / 10 + '0');
- date1 += (char)(ss % 10 + '0');
- cout << ip << ' ' << q << ' ' << name << " [" << d << yy << date1 << ' ' << t << "]" << extra << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement