Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Pr1VaporWinterSale {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(", ");
- Map<String, Double> gamePrice = new LinkedHashMap<>();
- Map<String, Double> gameContent = new LinkedHashMap<>();
- for (String s : input) {
- if (s.contains("-")) {
- String[] games = s.split("-");
- String nameGame = games[0];
- double price = Double.parseDouble(games[1]);
- if (!(gamePrice.containsKey(nameGame))) {
- gamePrice.put(nameGame, price);
- }
- } else if (s.contains(":")) {
- String[] games = s.split(":");
- String nameGame = games[0];
- String gameDLC = games[1];
- if (gamePrice.containsKey(nameGame)) {
- gameContent.put(nameGame + " - " + gameDLC, null);
- gameContent.put(nameGame + " - " + gameDLC, gamePrice.get(nameGame) * 1.2);
- gamePrice.remove(nameGame);
- }
- }
- }
- System.out.println();
- gameContent.entrySet()
- .stream()
- .sorted(Comparator.comparingDouble(Map.Entry::getValue))
- .forEach(e -> {
- gameContent.put(e.getKey(), e.getValue() * 0.5);
- System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
- });
- gamePrice.entrySet()
- .stream()
- .sorted(Map.Entry.<String, Double>comparingByValue().reversed())
- .forEach(e -> {
- gamePrice.put(e.getKey(), e.getValue() * 0.8);
- System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement