Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExamJavaAdvanced22Oct2017;
- import java.util.*;
- public class VLogger {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Map<String, followersFollowing> statistics = new HashMap<>();
- while (true) {
- String[] input = scan.nextLine().split(" ");
- if (input[0].equalsIgnoreCase("statistics")) {
- break;
- }
- if (input.length == 3) {
- if (statistics.containsKey(input[0]) && statistics.containsKey(input[2])) {
- if (!input[0].equals(input[2])) {
- statistics.get(input[0]).getFollowing().add(input[2]);
- statistics.get(input[2]).getFollowers().add(input[0]);
- }
- }
- }
- if (input.length == 4) {
- if (!statistics.containsKey(input[0])) {
- statistics.put(input[0], new followersFollowing());
- statistics.get(input[0]).setFollowers(new HashSet<>());
- statistics.get(input[0]).setFollowing(new HashSet<>());
- } else {
- continue;
- }
- }
- }
- System.out.println("The V-Logger has a total of " + statistics.size() + " vloggers in its logs.");
- final int[] counter = {1};
- statistics.entrySet()
- .stream()
- .sorted((y1, y2) -> Integer.valueOf(y1.getValue().getFollowing().size()).compareTo(Integer.valueOf(y2.getValue().getFollowing().size())))
- .sorted((x1, x2) -> Integer.valueOf(x2.getValue().getFollowers().size()).compareTo(Integer.valueOf(x1.getValue().getFollowers().size())))
- .forEach(x -> {
- if (counter[0] == 1) {
- System.out.println(counter[0] + ". " + x.getKey() + " : " + x.getValue().getFollowers().size() + " followers, " + x.getValue().getFollowing().size() + " following");
- x.getValue()
- .getFollowers()
- .stream()
- .sorted()
- .forEach(f -> System.out.println("* " + f));
- } else {
- System.out.println(counter[0] + ". " + x.getKey() + " : " + x.getValue().getFollowers().size() + " followers, " + x.getValue().getFollowing().size() + " following");
- }
- counter[0]++;
- }
- );
- }
- static class followersFollowing {
- public HashSet<String> followers;
- public HashSet<String> following;
- public HashSet<String> getFollowers() {
- return followers;
- }
- public void setFollowers(HashSet<String> followers) {
- this.followers = followers;
- }
- public HashSet<String> getFollowing() {
- return following;
- }
- public void setFollowing(HashSet<String> following) {
- this.following = following;
- }
- public followersFollowing(HashSet<String> followers, HashSet<String> following) {
- this.followers = followers;
- this.following = following;
- }
- public followersFollowing() {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement