Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- != 0) {
String s = sc.next();
int x = Integer.parseInt(s.substring(0, s.indexOf('-')));
int y = Integer.parseInt(s.substring(s.indexOf('-') + 1, s.lastIndexOf('-')));
int z = Integer.parseInt(s.substring(s.lastIndexOf('-') + 1));
if ((x % 400 == 0 || (x % 100 != 0 && x % 4 == 00)) && (y == 2 && z == 29)) {
System.out.println("-1");
} else {
if (y < 3) {
int num = 0;
for (int i = x; i < x + 18; i++) {
if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 00)) {
num += 366;
} else num += 365;
}
System.out.println(num);
} else {
int num = 0;
for (int i = x + 1; i <= x + 18; i++) {
if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 00)) {
num += 366;
} else num += 365;
}
System.out.println(num);
}
}
}
}
}