Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TechFundamentals;
- import com.sun.source.tree.WhileLoopTree;
- import java.util.*;
- public class array_temp {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, String> contestAndPass = new HashMap<>();
- String inputUser = scanner.nextLine();
- while (!inputUser.equals("end of contests")) {
- String[] tokens = inputUser.split(":");
- String contest = tokens[0];
- String pass = tokens[1];
- contestAndPass.put(contest, pass);
- inputUser = scanner.nextLine();
- }
- Map<String, Map<String, Integer>> contestUser = new TreeMap<>();
- String inputUsersContest = scanner.nextLine();
- while (!inputUsersContest.equals("end of submissions")) {
- String[] tokens = inputUsersContest.split("=>");
- String contest = tokens[0];
- String pass = tokens[1];
- String userName = tokens[2];
- int points = Integer.parseInt(tokens[3]);
- Map<String, Integer> subject = contestUser.get(userName);
- for (Map.Entry<String, String> entry : contestAndPass.entrySet()) {
- if (entry.getKey().equals(contest)) {
- if (entry.getValue().equals(pass)) {
- if (!contestUser.containsKey(userName)) {
- subject = new TreeMap<>();
- subject.put(contest, points);
- contestUser.put(userName, subject);
- } else {
- if (!subject.containsKey(contest)) {
- subject.put(contest, points);
- contestUser.put(userName, subject);
- } else {
- if (points > subject.get(contest))
- subject.put(contest, points);
- contestUser.put(userName, subject);
- }
- }
- }
- }
- }
- inputUsersContest = scanner.nextLine();
- }
- int bestPoint = 0;
- String bestName = "";
- for (Map.Entry<String, Map<String, Integer>> entry : contestUser.entrySet()) {
- int tempBestPoints = 0;
- Map<String, Integer> subject = entry.getValue();
- for (Map.Entry<String, Integer> e : subject.entrySet()) {
- tempBestPoints += e.getValue();
- }
- if (bestPoint < tempBestPoints) {
- bestPoint = tempBestPoints;
- bestName = entry.getKey();
- }
- }
- System.out.printf("Best candidate is %s with total %d points.%n", bestName, bestPoint);
- System.out.println("Ranking: ");
- for (Map.Entry<String, Map<String, Integer>> entry : contestUser.entrySet()) {
- System.out.printf("%s%n", entry.getKey());
- Map<String, Integer> subject = entry.getValue();
- subject.entrySet().stream().sorted((f, s) -> s.getValue().compareTo(f.getValue()))
- .forEach(e -> {
- System.out.printf("# %s -> %d%n", e.getKey(), e.getValue());
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement