Advertisement
aslv

Logs Aggregator

Jun 2nd, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.TreeMap;
  3. import java.util.TreeSet;
  4.  
  5.  
  6. public class Task4 {
  7.  
  8.     private static class Info {
  9.         public int duration;
  10.         public TreeSet<String> IPs;
  11.         public Info(int d, String IP) {
  12.             duration = d;
  13.             IPs = new TreeSet<String>() {{ add(IP); }};
  14.         }
  15.     }
  16.    
  17.     public static void main(String[] args) {
  18.         Scanner sc = new Scanner(System.in);
  19.         int n = sc.nextInt(); sc.nextLine();
  20.         String line, IP, name;
  21.         int duration;
  22.         String[] arguments;
  23.        
  24.         TreeMap<String, Info> data = new TreeMap<>();
  25.         Info temp;
  26.        
  27.         for (int i = 0; i < n; i++) {
  28.             line = sc.nextLine();
  29.             arguments = line.split(" ");
  30.             IP = arguments[0];
  31.             name = arguments[1];
  32.             duration = Integer.parseInt(arguments[2]);
  33.             if ((temp = data.putIfAbsent(name, new Info(duration, IP))) != null) {
  34.                 temp.duration += duration;
  35.                 temp.IPs.add(IP);
  36.                 data.put(name, temp);
  37.             }
  38.         }
  39.        
  40.         for (String _name : data.keySet()) {
  41.             temp = data.get(_name);
  42.             System.out.println(_name + ": " + temp.duration + " " + temp.IPs);
  43.         }
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement