Advertisement
Filkolev

Logs Aggregator

Jan 4th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Scanner;
  3. import java.util.TreeMap;
  4.  
  5. public class Veri {
  6.     public static void main(String[] args) {       
  7.         @SuppressWarnings("resource")
  8.         Scanner sc = new Scanner(System.in);
  9.         int n = sc.nextInt();
  10.         sc.nextLine();
  11.         TreeMap<String,Map<String,Integer>> result = new TreeMap<String, Map<String,Integer>>();
  12.        
  13.        
  14.         for (int i = 0; i <n ; i++) {
  15.             String[] line = sc.nextLine().split(" ");
  16.             String ip = line[0];
  17.             String name = line[1];
  18.             Integer duration = Integer.parseInt(line[2]);
  19.            
  20.             Map<String, Integer> durationAndIp= new TreeMap<String, Integer>();
  21.            
  22.             if(result.containsKey(name)){
  23.                 if(result.get(name).containsKey(ip)){
  24.                     int prevDuration = result.get(name).get(ip);
  25.                     duration += prevDuration;                  
  26.                 }
  27.                 result.get(name).put(ip, duration);
  28.             }else{
  29.                 durationAndIp.put(ip, duration);
  30.                 result.put(name,durationAndIp);
  31.             }          
  32.         }
  33.         System.out.println(result);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement