Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class _09_ForceBook {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- Map<String, List<String>> sidesWithUsers = new TreeMap<>();
- String input = "";
- while (!"Lumpawaroo".equals(input = reader.readLine())) {
- if (input.contains(" | ")) {
- String[] data = input.split(" \\| ");
- String side = data[0];
- String user = data[1];
- boolean exists = false;
- sidesWithUsers.putIfAbsent(side, new ArrayList<>());
- for (Map.Entry<String, List<String>> pair : sidesWithUsers.entrySet()) {
- List<String> users = pair.getValue();
- if (users.contains(user)) {
- exists = true;
- break;
- }
- }
- if (!exists) {
- sidesWithUsers.get(side).add(user);
- }
- } else if (input.contains(" -> ")) {
- String[] data = input.split(" -> ");
- String user = data[0];
- String side = data[1];
- sidesWithUsers.putIfAbsent(side, new ArrayList<>());
- for (Map.Entry<String, List<String>> pair : sidesWithUsers.entrySet()) {
- List<String> users = pair.getValue();
- if (users.contains(user)) {
- users.remove(user);
- break;
- }
- }
- sidesWithUsers.get(side).add(user);
- System.out.println(user + " joins the " + side + " side!");
- }
- }
- sidesWithUsers.entrySet().stream()
- .sorted((v1, v2) -> Integer.compare(v2.getValue().size(), v1.getValue().size()))
- .filter(e -> e.getValue().size() > 0)
- .forEach(kvp -> {
- System.out.println("Side: " + kvp.getKey() + ", " + "Members: " + kvp.getValue().size());
- Collections.sort(kvp.getValue());
- kvp.getValue().forEach(user -> {
- System.out.println("! " + user);
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement