GastonFontenla

Untitled

May 29th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Fecha
  6. {
  7.     int y, m, d;
  8.  
  9.     int getDays()
  10.     {
  11.         return d + m*31 + y*31*12;
  12.     }
  13. };
  14.  
  15. int main()
  16. {
  17.     int tc;
  18.     string a, b; ///ambas fechas
  19.  
  20.     cin >> tc;
  21.  
  22.     for(int i=0; i<tc; i++)
  23.     {
  24.         cin >> a >> b;
  25.  
  26.         Fecha f1, f2;
  27.         f1.d = (a[0]-'0')*10 + (a[1]-'0');
  28.         f1.m = (a[3]-'0')*10 + (a[4]-'0');
  29.         f1.y = (a[6]-'0')*1000 + (a[7]-'0')*100 + (a[8]-'0')*10 + (a[9]-'0');
  30.  
  31.         f2.d = (b[0]-'0')*10 + (b[1]-'0');
  32.         f2.m = (b[3]-'0')*10 + (b[4]-'0');
  33.         f2.y = (b[6]-'0')*1000 + (b[7]-'0')*100 + (b[8]-'0')*10 + (b[9]-'0');
  34.  
  35.         if(f1.getDays() < f2.getDays())
  36.         {
  37.             cout << "Case #" << i+1 << ": Invalid birth date" << endl;
  38.         }
  39.         else
  40.         {
  41.             int age = (f1.y - f2.y - 1 + (f1.m > f2.m || (f1.m == f2.m && f1.d >= f2.d)));
  42.  
  43.             if(age > 130)
  44.             {
  45.                 cout << "Case #" << i+1 << ": Check birth date" << endl;
  46.             }
  47.             else
  48.             {
  49.                 cout << "Case #" << i+1 << ": " << age << endl;
  50.             }
  51.         }
  52.     }
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment