Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Locale;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class _4_ActivityTracker {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Locale.setDefault(Locale.ROOT);
- Scanner scan = new Scanner(System.in);
- int count = scan.nextInt();
- TreeMap<Integer, TreeMap<String, Integer>> monthsActivity = new TreeMap<>();
- for (int i = 0; i < count; i++) {
- String dateStr = scan.next();
- String[] splittedString = dateStr.split("/");
- int month = Integer.parseInt(splittedString[1]);
- String userName = scan.next();
- int distance = scan.nextInt();
- scan.nextLine();
- TreeMap<String, Integer> usersActivity;
- if (!monthsActivity.containsKey(month)) {
- usersActivity = new TreeMap<>();
- usersActivity.put(userName, distance);
- } else {
- usersActivity = monthsActivity.get(month);
- Integer previous = usersActivity.get(userName);
- if (previous == null) {
- previous = 0;
- }
- usersActivity.put(userName, previous + distance);
- }
- monthsActivity.put(month, usersActivity);
- }
- for (Integer month : monthsActivity.keySet()) {
- System.out.print(month + ": ");
- TreeMap<String, Integer> userActivity = monthsActivity.get(month);
- boolean isFirst = true;
- for (String user : userActivity.keySet()) {
- if (!isFirst) {
- System.out.print(", ");
- }
- isFirst = false;
- System.out.print(user + "(");
- System.out.print(userActivity.get(user) + ")");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement