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    2 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!

User Avatar JoonYorigami    Created at    1 likes

There are cases where your solution could go wrong! The idea is to convert the years and months into days, so that we can add them up and compare them, whoever has a lower total will be the one to have been born first/older.\ 1 year = 365 days\ 1 month = 31 days (at most)\ 1 day = 1 day ```python a,b,c,x,y,z = map(int,input().split()) Person1_days_total = a + b*31 + c*365 Person2_days_total = x + y*31 + z*365 if Person1_days_total < Person2_days_total: #Since Person1 has a lower total, this means they were born first print(1) else: #Otherwise, Person2 was born first since they're guaranteed to never be born on the same day print(2) ```