import java.util.Scanner;
import java.io.FileReader;
import java.io.IOException;
class Main
{
public static final boolean DEBUG = false;
public static int days[] = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public static boolean isLeap(int y)
{
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) return true;
return false;
}
public static void main(String[] args) throws IOException
{
Scanner cin;
String s1, s2;
int y1, m1, d1, y2, m2, d2;
if (DEBUG) {
cin = new Scanner(new FileReader("d:\\OJ\\uva_in.txt"));
} else {
cin = new Scanner(System.in);
}
while (cin.hasNext()) {
s1 = cin.next();
s2 = cin.next();
String tmp1 = s1.substring(0, 4);
y1 = Integer.parseInt(tmp1);
tmp1 = s1.substring(4, 6);
m1 = Integer.parseInt(tmp1);
tmp1 = s1.substring(6);
d1 = Integer.parseInt(tmp1);
tmp1 = s2.substring(0, 4);
y2 = Integer.parseInt(tmp1);
tmp1 = s2.substring(4, 6);
m2 = Integer.parseInt(tmp1);
tmp1 = s2.substring(6);
d2 = Integer.parseInt(tmp1);
if (y1 > y2 || (y1 == y2 && m1 > m2) || (y1 == y2 && m1 == m2 && d1 > d2)) {
int tmp;
tmp = y1;
y1 = y2;
y2 = tmp;
tmp = m1;
m1 = m2;
m2 = tmp;
tmp = d1;
d1 = d2;
d2 = tmp;
}
int days1 = 0;
for (int i = 0; i < m1 - 1; i++) {
days1 += days[i];
if (i == 1) {
if (isLeap(y1)) days1++;
}
}
days1 += d1;
int days2 = 0;
for (int i = 0; i < m2 - 1; i++) {
days2 += days[i];
if (i == 1) {
if (isLeap(y2)) days2++;
}
}
days2 += d2;
int ans = 0;
if (y1 == y2) {
ans = days2 - days1 + 1;
} else {
for (int i = y1 + 1; i < y2; i++) {
ans += 365;
if (isLeap(i)) ans++;
}
ans += 365 - days1 + 1;
if (isLeap(y1)) ans++;
ans += days2;
}
System.out.println(ans);
}
}
}
题目1096:日期差值
最新推荐文章于 2022-05-02 09:59:38 发布