Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.TreeSet;
- public class _4_LogsAggregator {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- int count = scan.nextInt();
- scan.nextLine();
- TreeMap<String, Integer> durations = new TreeMap<>();
- HashMap<String, TreeSet<String>> ipAddresses = new HashMap<>();
- for (int i = 0; i < count; i++) {
- String ipStr = scan.next();
- String userName = scan.next();
- String durStr = scan.next();
- int duration = Integer.parseInt(durStr);
- Integer previousDuration = durations.get(userName);
- if (previousDuration == null) {
- previousDuration = 0;
- }
- durations.put(userName, previousDuration + duration);
- TreeSet<String> ipSet = ipAddresses.get(userName);
- if (ipSet == null) {
- ipSet = new TreeSet<>();
- }
- ipSet.add(ipStr);
- ipAddresses.put(userName, ipSet);
- scan.nextLine();
- }
- for (Entry<String, Integer> userNameAndDuration : durations.entrySet()) {
- String userName = userNameAndDuration.getKey();
- int duration = userNameAndDuration.getValue();
- TreeSet<String> ipSet = ipAddresses.get(userName);
- System.out.println(userName + ": " + duration + " " + ipSet);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement