Date comparison
D105 – Time Limit: 1.000 s – Memory Limit: 256 MB
Write a program to compare two dates: y1−m1−d1 and y2−m2−d2.
Input and Output
The input consists of two lines. The first line contains y1, m1 and d1 separated by spaces. The second line contains y1, m1 and d1 separated by spaces.
1000≤y1,y2≤9999, and the dates are guaranteed to be valid.
If y1−m1−d1 is earlier, output Before
.
If y2−m2−d2 is earlier, output After
.
If the two dates are the same, output Same
.
Sample Tests
Input | Output | |
---|---|---|
1 | 2015 3 1 2015 7 5 |
Before |
2 | 2014 6 20 2012 11 2 |
After |
3 | 2046 5 13 2046 5 13 |
Same |
Solutions
Note: There are many other algorithms/implementations that can solve this task correctly.
C++
#include <iostream>
using namespace std;
int main() {
int y1, m1, d1, y2, m2, d2;
cin >> y1 >> m1 >> d1;
cin >> y2 >> m2 >> d2;
int a = 10000 * y1 + 100 * m1 + d1;
int b = 10000 * y2 + 100 * m2 + d2;
if (a < b) {
cout << "Before" << endl;
} else if (a == b) {
cout << "Same" << endl;
} else {
cout << "After" << endl;
}
return 0;
}
Python
y1, m1, d1 = map(int, input().split())
y2, m2, d2 = map(int, input().split())
a = 10000 * y1 + 100 * m1 + d1
b = 10000 * y2 + 100 * m2 + d2
if a < b:
print('Before')
elif a == b:
print('Same')
else:
print('After')
Hidden Tests
Input | Output | |
---|---|---|
4 | 2015 11 30 2015 12 1 |
Before |
5 | 2000 9 2 2000 9 2 |
Same |
6 | 2000 9 2 2000 9 3 |
Before |
7 | 2000 9 3 2000 9 2 |
After |
8 | 2000 10 1 2000 9 5 |
After |
9 | 2000 8 21 2000 9 3 |
Before |
10 | 2004 2 29 2046 3 01 |
Before |
11 | 2006 1 1 2005 12 31 |
After |
12 | 1000 1 1 9999 12 31 |
Before |
13 | 9876 12 31 9877 1 1 |
Before |