fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String[] arr = {"01 03 2007 09 36 146.102.174.177 GET",
  14. "01 03 2007 10 52 146.102.174.177 GET",
  15. "11 06 2027 09 52 146.102.174.177 GET",
  16. "05 03 2007 02 52 166.132.174.177 GET",
  17. "09 09 2017 09 52 146.102.174.177 GET",
  18. "01 03 2007 17 52 136.102.124.177 GET"};
  19. HashSet<Date> set = new HashSet();
  20. Scanner in = new Scanner(System.in);
  21. SimpleDateFormat formatter = new SimpleDateFormat("dd MM yyyy HH mm");
  22. for(String l: arr){
  23. String[] line = l.split(" ", 6);
  24. Date date = formatter.parse(line[0] + " " + line[1] + " " +
  25. line[2] + " " + line[3] + " " + line[4]);
  26. set.add(date);
  27. }
  28. System.out.println("Введите номер часа");
  29. int hours = in.nextInt();
  30. int count = 0;
  31. for(Date date: set){
  32. Calendar calendar = GregorianCalendar.getInstance();
  33. calendar.setTime(date);
  34. if(hours == calendar.get(Calendar.HOUR_OF_DAY)){
  35. count++;
  36. System.out.println(formatter.format(date));
  37. }
  38. }
  39. System.out.println("Выведено дат: " + count);
  40. System.out.println("Всего дат: " + set.size());
  41. }
  42. }
Success #stdin #stdout 0.07s 4386816KB
stdin
9
stdout
Введите номер часа
09 09 2017 09 52
01 03 2007 09 36
11 06 2027 09 52
Выведено дат: 3
Всего дат: 6