Solutions of Age - MarisaOJ: Marisa Online Judge

Solutions of Age

Select solution language

Write solution here.


fdsfdfsf    Created at    8 likes

trong bài này ta sẽ thực hiện so sánh năm của 2 người, nếu = nhau thì so sánh tháng nếu = thì so sánh tuổi ( nếu > thì sẽ ít tuổi hơn và ngược lại)

User Avatar HuyNguyenCong    Created at    0 likes

# AGE --- ## 🧠 HOW TO SOLVE THIS PROBLEM? When comparing two people to see who is older, we must consider the following cases: - Compare year -> smaller year -> older. - If years are the same, compare month -> smaller month -> older. - If months are the same, compare day -> smaller day -> older. --- ## 📜 FULL CODE ### 🔹C++ ```cpp #include <iostream> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c, x, y, z; cin >> a >> b >> c >> x >> y >> z; if (c != z) { if (c < z) cout << 1; else cout << 2; } else { if (b != y) { if (b < y) cout << 1; else cout << 2; } else { if (a < x) cout << 1; else cout << 2; } } return 0; } ``` ### 🔹Python ```python a, b, c, x, y, z = map(int, input().split()) print(1 if (c, b, a) < (z, y, x) else 2) ``` --- ## HAPPY CODING!