Untitled
unknown
c_cpp
5 months ago
1.1 kB
2
Indexable
#include <iostream> #include <string> using namespace std; int main() { string n; int d, m, y; bool isLeap = 1; cin >> n; d = (int) (n[0] - 48) * 10 + (int) (n[1] - 48); m = (int) (n[3] - 48) * 10 + (int) (n[4] - 48); y = (int) (n[6] - 48) * 1000 + (int) (n[7] - 48) * 100 + (int) (n[8] - 48) * 10 + (int) (n[9] - 48); switch (m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (d <= 31) { cout << "yes"; } else { cout << "no"; } break; case 4: case 6: case 9: case 11: if (d <= 30) { cout << "yes"; } else { cout << "no"; } break; case 2: isLeap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0); if (d <= (isLeap ? 29 : 28)) { cout << "yes"; } else { cout << "no"; } break; default: cout << "no"; break; } return 0; }
Editor is loading...
Leave a Comment