Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package JavaSyntax;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class P11_GameOfNames {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- long maxValue = Long.MIN_VALUE;
- String winnerName = "";
- boolean isRightLength = false;
- Map<String, Long> map = new HashMap<>();
- for (int i = 0; i < n; i++) {
- String name = scanner.nextLine();
- long initialScore = Long.parseLong(scanner.nextLine());
- if (name.length() > 2 && name.length() < 31) {
- isRightLength = true;
- long copyScore = initialScore;
- for (int j = 0; j < name.length(); j++) {
- long charScore = name.charAt(j);
- if (charScore % 2 != 0) {
- copyScore -= charScore;
- } else {
- copyScore += charScore;
- }
- }
- map.putIfAbsent(name, copyScore);
- for (int j = 0; j < map.size(); j++) {
- if (map.get(name) > maxValue) {
- maxValue = map.get(name);
- winnerName = name;
- }
- }
- }
- }
- // Map.Entry<String, Integer> max = map.entrySet()
- // .stream()
- // .sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue()))
- // .findFirst()
- // .get();
- //
- // System.out.printf("The winner is %s - %d points", max.getKey(), max.getValue());
- if (isRightLength) {
- System.out.printf("The winner is %s - %d points", winnerName, maxValue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment