Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class Veri {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- sc.nextLine();
- TreeMap<String,Map<String,Integer>> result = new TreeMap<String, Map<String,Integer>>();
- for (int i = 0; i <n ; i++) {
- String[] line = sc.nextLine().split(" ");
- String ip = line[0];
- String name = line[1];
- Integer duration = Integer.parseInt(line[2]);
- Map<String, Integer> durationAndIp= new TreeMap<String, Integer>();
- if(result.containsKey(name)){
- if(result.get(name).containsKey(ip)){
- int prevDuration = result.get(name).get(ip);
- duration += prevDuration;
- }
- result.get(name).put(ip, duration);
- }else{
- durationAndIp.put(ip, duration);
- result.put(name,durationAndIp);
- }
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement