Advertisement
nikeza

Vapor Winter Sale

Jul 30th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. package TechFundamentals;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.InputStreamReader;
  6. import java.text.DecimalFormat;
  7. import java.util.*;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. import java.util.stream.Collectors;
  11.  
  12. public class temp_Home_Work {
  13.  
  14.  
  15.     public static void main(String[] args) {
  16.         Scanner scanner = new Scanner(System.in);
  17.  
  18.         String[] input = scanner.nextLine().split(", ");
  19.  
  20.         Map<String, List<String>> game = new HashMap<>();
  21.  
  22.         for (int i = 0; i < input.length; i++) {
  23.             if (input[i].contains("-")) {
  24.                 String[] tokens = input[i].split("-");
  25.  
  26.                 String nameGame = tokens[0];
  27.                 String price = tokens[1];
  28.  
  29.                 List<String> priceAndDLCs = game.get(nameGame);
  30.                 if (!game.containsKey(nameGame)) {
  31.                     priceAndDLCs = new ArrayList<>();
  32.                     priceAndDLCs.add(price);
  33.                     game.put(nameGame, priceAndDLCs);
  34.                 }
  35.  
  36.             } else {
  37.                 String[] tokensDLCs = input[i].split(":");
  38.                 String name = tokensDLCs[0];
  39.                 String dlc = tokensDLCs[1];
  40.                 if (game.containsKey(name)) {
  41.                     String price = game.get(name).get(0);
  42.                     double priceDouble = Double.parseDouble(price) * 1.2;
  43.                     String priceAvterDouble = priceDouble + "";
  44.                     game.get(name).set(0, priceAvterDouble);
  45.                     game.get(name).add(dlc);
  46.  
  47.                 }
  48.  
  49.             }
  50.         }
  51.  
  52.         for (Map.Entry<String, List<String>> entry : game.entrySet()) {
  53.             String price = entry.getValue().get(0);
  54.             if (entry.getValue().size() < 2) {
  55.                 double priceLower = Double.parseDouble(price) * 0.8;
  56.                 String priceAvterLower = priceLower + "";
  57.                 entry.getValue().set(0, priceAvterLower);
  58.             } else {
  59.                 double priceLower = Double.parseDouble(price) * 0.5;
  60.                 String priceAvterLower = priceLower + "";
  61.                 entry.getValue().set(0, priceAvterLower);
  62.             }
  63.  
  64.         }
  65.  
  66.         game.entrySet().stream()
  67.                 .filter(a -> a.getValue().size() > 1)
  68.                 .sorted((f, s) -> {
  69.                     double one = Double.parseDouble(f.getValue().get(0));
  70.                     double two = Double.parseDouble(s.getValue().get(0));
  71.                     return Double.compare(one, two);
  72.                 })
  73.                 .forEach(e -> System.out.printf("%s - %s - %.2f%n",
  74.                         e.getKey(), e.getValue().get(1), Double.parseDouble(e.getValue().get(0))));
  75.  
  76.         game.entrySet().stream()
  77.                 .filter(a -> a.getValue().size() == 1)
  78.                 .sorted((f, s) -> {
  79.                     double one = Double.parseDouble(f.getValue().get(0));
  80.                     double two = Double.parseDouble(s.getValue().get(0));
  81.                     return Double.compare(two, one);
  82.                 })
  83.                 .forEach(e ->
  84.                         System.out.printf("%s - %.2f%n",
  85.                                 e.getKey(), Double.parseDouble(e.getValue().get(0))));
  86.  
  87.  
  88.  
  89.     }
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement