Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.TreeSet;
- public class Task4 {
- private static class Info {
- public int duration;
- public TreeSet<String> IPs;
- public Info(int d, String IP) {
- duration = d;
- IPs = new TreeSet<String>() {{ add(IP); }};
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt(); sc.nextLine();
- String line, IP, name;
- int duration;
- String[] arguments;
- TreeMap<String, Info> data = new TreeMap<>();
- Info temp;
- for (int i = 0; i < n; i++) {
- line = sc.nextLine();
- arguments = line.split(" ");
- IP = arguments[0];
- name = arguments[1];
- duration = Integer.parseInt(arguments[2]);
- if ((temp = data.putIfAbsent(name, new Info(duration, IP))) != null) {
- temp.duration += duration;
- temp.IPs.add(IP);
- data.put(name, temp);
- }
- }
- for (String _name : data.keySet()) {
- temp = data.get(_name);
- System.out.println(_name + ": " + temp.duration + " " + temp.IPs);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement