|
|
вернуться в форумIs d2 redundant? Can't understand why we need date starting from which person was the oldest. Also can't understand why this solution gets WA3. Can anyone help? import java.util.GregorianCalendar; import java.util.Scanner; public class P1759 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.valueOf(scanner.nextLine()); GregorianCalendar birth = (GregorianCalendar) GregorianCalendar.getInstance(); GregorianCalendar death = (GregorianCalendar) GregorianCalendar.getInstance(); long max = 0; int result = 0; long longestLiveDeath = 0; for (int i = 0; i < n; i++) { String[] dates = scanner.nextLine().split("\\s"); set(birth, dates[0]); set(death, dates[2]); long liveTime = death.getTimeInMillis() - birth.getTimeInMillis(); if (liveTime > max || (liveTime == max && death.getTimeInMillis() < longestLiveDeath)) { max = liveTime; longestLiveDeath = death.getTimeInMillis(); result = i; } } System.out.println(result + 1); } private static void set(GregorianCalendar date, String sDate) { String[] split = sDate.split("\\."); date.set(Integer.valueOf(split[2]), Integer.valueOf(split[1]), Integer.valueOf(split[0])); } } Edited by author 24.03.2011 13:45 |
|
|