Advertisement
anon20016

A reworked

Nov 14th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <stack>
  8.  
  9. using namespace std;
  10.  
  11. pair<int, int> dec(pair<int, int> a, pair<int, int> b) {
  12. if (a.second < b.second) {
  13. a.second += 60;
  14. a.first--;
  15. }
  16. return { a.first - b.first, a.second - b.second };
  17. }
  18.  
  19. pair<int, int> r(string a, string b) {
  20. pair<int, int> d1 = { (a[1] - '0') * 10 + (a[2] - '0'), (a[3] - '0') * 10 + (a[4] - '0') };
  21. pair<int, int> d2 = { (b[1] - '0') * 10 + (b[2] - '0'), (b[3] - '0') * 10 + (b[4] - '0') };
  22.  
  23. if (a[0] != b[0]) {
  24. if (a[0] == '-') {
  25. return { d1.first + d2.first + (d1.second + d2.second) / 60, (d1.second + d2.second) % 60 };
  26. }
  27. return { -(d1.first + d2.first) + (d1.second + d2.second) / 60, (d1.second + d2.second) % 60 };
  28. }
  29. if (a[0] == '-') {
  30. if (d1 > d2) {
  31. return dec(d1, d2);
  32. }
  33. auto v = dec(d2, d1);
  34. v.first *= -1;
  35. return v;
  36. }
  37.  
  38. if (d1 < d2) {
  39. return dec(d2, d1);
  40. }
  41. auto v = dec(d1, d2);
  42. v.first *= -1;
  43. return v;
  44. }
  45.  
  46.  
  47.  
  48. int main() {
  49. freopen("input.txt", "r", stdin);
  50. freopen("output.txt", "w", stdout);
  51.  
  52. map<string, int> month;
  53. month["Jan"] = 1;
  54. month["Feb"] = 2;
  55. month["Mar"] = 3;
  56. month["Apr"] = 4;
  57. month["May"] = 5;
  58. month["Jun"] = 6;
  59. month["Jul"] = 7;
  60. month["Aug"] = 8;
  61. month["Sep"] = 9;
  62. month["Oct"] = 10;
  63. month["Nov"] = 11;
  64. month["Dec"] = 12;
  65.  
  66. vector<int> kd = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  67. vector<string> mnth = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  68.  
  69. string t;
  70. getline(cin, t);
  71. string ip, q, name, d, p, extra;
  72. while (cin >> ip) {
  73. cin >> q >> name;
  74. cin >> d;
  75. d.erase(d.begin());
  76. cin >> p;
  77. p.erase(p.begin() + 5);
  78. getline(cin, extra);
  79.  
  80. auto v = r(p, t);
  81. if (v.first < 0) {
  82. v.second *= -1;
  83. }
  84.  
  85. int dd = (d[0] - '0') * 10 + (d[1] - '0');
  86. string M = " ";
  87. M[0] = d[3];
  88. M[1] = d[4];
  89. M[2] = d[5];
  90. int mm = month[M];
  91. int yy = (d[7] - '0') * 1000 + (d[8] - '0') * 100 + (d[9] - '0') * 10 + (d[10] - '0');
  92. int hh = (d[12] - '0') * 10 + (d[13] - '0');
  93. int mn = (d[15] - '0') * 10 + (d[16] - '0');
  94. int ss = (d[18] - '0') * 10 + (d[19] - '0');
  95.  
  96. if (yy % 4 == 0) {
  97. kd[2]++;
  98. }
  99.  
  100. mn += v.second;
  101. if (mn > 59) {
  102. hh++;
  103. mn = mn % 60;
  104. }
  105. else
  106. if (mn < 0) {
  107. mn += 60;
  108. hh--;
  109. }
  110.  
  111. hh += v.first;
  112. if (hh > 23) {
  113. dd++;
  114. hh %= 24;
  115. }
  116. else {
  117. if (hh < 0) {
  118. hh += 24;
  119. dd--;
  120. }
  121. }
  122.  
  123. if (dd > kd[mm]) {
  124. mm++;
  125. dd = 1;
  126. if (mm == 13) {
  127. yy++;
  128. mm = 1;
  129. }
  130. }
  131. if (dd == 0) {
  132. if (mm == 1) {
  133. yy--;
  134. mm = 12;
  135. dd = 31;
  136. }
  137. else {
  138. mm--;
  139. dd = kd[mm];
  140. }
  141. }
  142.  
  143.  
  144. d = "";
  145. d += (char)(dd / 10 + '0');
  146. d += (char)(dd % 10 + '0');
  147. d += "/" + mnth[mm] + "/";
  148.  
  149. string date1 = ":";
  150. date1 += (char)(hh / 10 + '0');
  151. date1 += (char)(hh % 10 + '0');
  152. date1 += ':';
  153. date1 += (char)(mn / 10 + '0');
  154. date1 += (char)(mn % 10 + '0');
  155. date1 += ':';
  156. date1 += (char)(ss / 10 + '0');
  157. date1 += (char)(ss % 10 + '0');
  158.  
  159.  
  160. cout << ip << ' ' << q << ' ' << name << " [" << d << yy << date1 << ' ' << t << "]" << extra << endl;
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement