Advertisement
DatProgrammer

P58459

Oct 10th, 2015
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool leap_year (int y) {
  5.  
  6.   bool leap = false;
  7.   if (y%4 == 0 and y%100 != 0) leap = true;
  8.   else if (y%100 == 0 and (y/100)%4 == 0) leap = true;
  9.   //else;
  10.   return leap;
  11. }
  12.  
  13. bool is_valid_date(int d, int m, int y) {
  14.  
  15.   bool z = false;
  16.  
  17.   if ((m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12) and (d > 0 and d <= 31)) z = true;
  18.   else if (m == 2) {
  19.     if (leap_year(y) == true) {
  20.       if (d > 0 and d <= 29) z = true;
  21.     }
  22.     if (leap_year(y) == false) {
  23.       if (d > 0 and d <= 28) z = true;
  24.     }
  25.   }
  26.   else if (m > 0 and m < 12) {
  27.     if (d <= 30 and d > 0) z = true;
  28.   }
  29.   //else;
  30.  
  31.   return z;
  32.  
  33. }
  34.  
  35. int main() {
  36.  
  37.   int d, m, y;
  38.   cin >> d >> m >> y;
  39.   if (is_valid_date(d, m, y) == true) cout << "true" << endl;
  40.   else cout << "false" << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement