fork(1) download
  1. import java.io.BufferedOutputStream;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.Calendar;
  7. import java.util.Collections;
  8.  
  9. public class Main {
  10.  
  11. public static void main(String[] args) throws IOException {
  12.  
  13. ArrayList<Calendar> citas = new ArrayList<Calendar>();
  14. ArrayList<String> citasString = new ArrayList<String>();
  15. String[] datos1, datos2;
  16. Calendar hora;
  17. int i, numCitas, horas, minutos, posicion;
  18. long segundos;
  19. int contador = 0;
  20. String linea = entrada.readLine();
  21. while (linea != null) {
  22. contador++;
  23. numCitas = Integer.parseInt(linea);
  24. hora = Calendar.getInstance();
  25. hora.set(2001, 10, 1, 10, 0);
  26. citas.add(hora);
  27. citasString.add("10:00");
  28. hora = Calendar.getInstance();
  29. hora.set(2001, 10, 1, 18, 0);
  30. citas.add(hora);
  31. citasString.add("18:00");
  32. for (i = 0; i < numCitas; i++) {
  33. datos1 = entrada.readLine().split(" ");
  34. datos2 = datos1[0].split(":");
  35. horas = Integer.parseInt(datos2[0]);
  36. minutos = Integer.parseInt(datos2[1]);
  37. hora = Calendar.getInstance();
  38. hora.set(2001, 10, 1, horas, minutos);
  39. citas.add(hora);
  40. citasString.add(datos1[0]);
  41. datos2 = datos1[1].split(":");
  42. horas = Integer.parseInt(datos2[0]);
  43. minutos = Integer.parseInt(datos2[1]);
  44. hora = Calendar.getInstance();
  45. hora.set(2001, 10, 1, horas, minutos);
  46. citas.add(hora);
  47. citasString.add(datos1[1]);
  48. }
  49. Collections.sort(citas);
  50. Collections.sort(citasString);
  51. segundos = 0;
  52. posicion = 0;
  53. for (i = 0; i < citas.size(); i = i + 2) {
  54. if (citas.get(i + 1).getTimeInMillis() - citas.get(i).getTimeInMillis() > segundos) {
  55. posicion = i;
  56. segundos = citas.get(i + 1).getTimeInMillis() - citas.get(i).getTimeInMillis();
  57. }
  58. }
  59. segundos = segundos / 1000;
  60. minutos = (int) (segundos / 60);
  61. if (minutos < 60) {
  62. salida.write(("Day #" + contador + ": the longest nap starts at " + citasString.get(posicion) + " and will last for " + minutos + " minutes.\n").getBytes());
  63. } else {
  64. horas = minutos / 60;
  65. minutos = minutos % 60;
  66. salida.write(("Day #" + contador + ": the longest nap starts at " + citasString.get(posicion) + " and will last for " + horas + " hours and " + minutos + " minutes.\n").getBytes());
  67. }
  68. citas.clear();
  69. citasString.clear();
  70. linea = entrada.readLine();
  71. }
  72. salida.flush();
  73. salida.close();
  74. }
  75. }
Success #stdin #stdout 0.1s 380480KB
stdin
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
13:00 15:00 Boring lectures...
15:30 17:45 Reading
4
10:00 12:00 Lectures
12:00 13:00 Lunch, just lunch.
13:00 15:00 Lectures, lectures... oh, no!
16:45 17:45 Reading (to be or not to be?)
4
10:00 12:00 Lectures, as everyday.
12:00 13:00 Lunch, again!!!
13:00 15:00 Lectures, more lectures!
15:30 17:15 Reading (I love reading, but should I schedule it?)
1
12:00 13:00 I love lunch! Have you ever noticed it? :)
stdout
Day #1: the longest nap starts at 15:00 and will last for 30 minutes.
Day #2: the longest nap starts at 15:00 and will last for 1 hours and 45 minutes.
Day #3: the longest nap starts at 17:15 and will last for 45 minutes.
Day #4: the longest nap starts at 13:00 and will last for 5 hours and 0 minutes.