prestige

Untitled

May 12th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <string>
  4. using namespace std;
  5. int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  6. int main () {
  7. time_t now;
  8. struct tm dt1;
  9. struct tm dt2;
  10. time(&now);
  11. dt1 = *localtime(&now);
  12. dt2 = *localtime(&now);
  13. string s1, s2;
  14. cin >> s1 >> s2;
  15. int m1 = 0, d1 = 0, y1 = 0;
  16. int m2 = 0, d2 = 0, y2 = 0;
  17. int k = 1;
  18. int cc = 0;
  19. for (int i = s1.length() -1; i >= 0; i--) {
  20. char c = s1[i];
  21. if (c ==':') {
  22. k = 1;
  23. cc++;
  24. continue;
  25. } else if (cc == 0) {
  26. d1 += (k * int(c - '0'));
  27. k *= 10;
  28. } else if (cc == 1) {
  29. m1 += (k * int(c - '0'));
  30. k *= 10;
  31. } else if (cc == 2) {
  32. y1 += (k * int(c - '0'));
  33. k *= 10;
  34. }
  35. }
  36. k = 1;
  37. cc = 0;
  38. for (int i = s2.length() -1; i >= 0; i--) {
  39. char c = s2[i];
  40. if (c ==':') {
  41. k = 1;
  42. cc++;
  43. continue;
  44. } else if (cc == 0) {
  45. d2 += (k * int(c - '0'));
  46. k *= 10;
  47. } else if (cc == 1) {
  48. m2 += (k * int(c - '0'));
  49. k *= 10;
  50. } else if (cc == 2) {
  51. y2 += (k * int(c - '0'));
  52. k *= 10;
  53. }
  54. }
  55. dt1.tm_hour = 0; dt1.tm_min = 0; dt1.tm_sec = 0;
  56. dt1.tm_mday = d1, dt1.tm_mon = m1, dt1.tm_year = y1;
  57.  
  58. dt2.tm_hour = 0; dt2.tm_min = 0; dt2.tm_sec = 0;
  59. dt2.tm_mday = d2, dt2.tm_mon = m2, dt2.tm_year = y2;
  60. double s = difftime(mktime(&dt1), mktime(&dt2));
  61. cout << s / 86400;
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment