Advertisement
mirozspace

VWS

Apr 2nd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Pr1VaporWinterSale {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String[] input = scanner.nextLine().split(", ");
  8.  
  9.         Map<String, Double> gamePrice = new LinkedHashMap<>();
  10.         Map<String, Double> gameContent = new LinkedHashMap<>();
  11.  
  12.  
  13.         for (String s : input) {
  14.             if (s.contains("-")) {
  15.                 String[] games = s.split("-");
  16.                 String nameGame = games[0];
  17.                 double price = Double.parseDouble(games[1]);
  18.                 if (!(gamePrice.containsKey(nameGame))) {
  19.                     gamePrice.put(nameGame, price);
  20.                 }
  21.             } else if (s.contains(":")) {
  22.                 String[] games = s.split(":");
  23.                 String nameGame = games[0];
  24.                 String gameDLC = games[1];
  25.                 if (gamePrice.containsKey(nameGame)) {
  26.                     gameContent.put(nameGame + " - " + gameDLC, null);
  27.                     gameContent.put(nameGame + " - " + gameDLC, gamePrice.get(nameGame) * 1.2);
  28.                     gamePrice.remove(nameGame);
  29.                 }
  30.             }
  31.         }
  32.         System.out.println();
  33.         gameContent.entrySet()
  34.                 .stream()
  35.                 .sorted(Comparator.comparingDouble(Map.Entry::getValue))
  36.                 .forEach(e -> {
  37.                     gameContent.put(e.getKey(), e.getValue() * 0.5);
  38.                     System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
  39.                 });
  40.  
  41.         gamePrice.entrySet()
  42.                 .stream()
  43.                 .sorted(Map.Entry.<String, Double>comparingByValue().reversed())
  44.                 .forEach(e -> {
  45.                     gamePrice.put(e.getKey(), e.getValue() * 0.8);
  46.                     System.out.printf("%s - %.2f%n", e.getKey(), e.getValue());
  47.                 });
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement