Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TechFundamentals;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class temp_Home_Work {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(", ");
- Map<String, List<String>> game = new HashMap<>();
- for (int i = 0; i < input.length; i++) {
- if (input[i].contains("-")) {
- String[] tokens = input[i].split("-");
- String nameGame = tokens[0];
- String price = tokens[1];
- List<String> priceAndDLCs = game.get(nameGame);
- if (!game.containsKey(nameGame)) {
- priceAndDLCs = new ArrayList<>();
- priceAndDLCs.add(price);
- game.put(nameGame, priceAndDLCs);
- }
- } else {
- String[] tokensDLCs = input[i].split(":");
- String name = tokensDLCs[0];
- String dlc = tokensDLCs[1];
- if (game.containsKey(name)) {
- String price = game.get(name).get(0);
- double priceDouble = Double.parseDouble(price) * 1.2;
- String priceAvterDouble = priceDouble + "";
- game.get(name).set(0, priceAvterDouble);
- game.get(name).add(dlc);
- }
- }
- }
- for (Map.Entry<String, List<String>> entry : game.entrySet()) {
- String price = entry.getValue().get(0);
- if (entry.getValue().size() < 2) {
- double priceLower = Double.parseDouble(price) * 0.8;
- String priceAvterLower = priceLower + "";
- entry.getValue().set(0, priceAvterLower);
- } else {
- double priceLower = Double.parseDouble(price) * 0.5;
- String priceAvterLower = priceLower + "";
- entry.getValue().set(0, priceAvterLower);
- }
- }
- game.entrySet().stream()
- .filter(a -> a.getValue().size() > 1)
- .sorted((f, s) -> {
- double one = Double.parseDouble(f.getValue().get(0));
- double two = Double.parseDouble(s.getValue().get(0));
- return Double.compare(one, two);
- })
- .forEach(e -> System.out.printf("%s - %s - %.2f%n",
- e.getKey(), e.getValue().get(1), Double.parseDouble(e.getValue().get(0))));
- game.entrySet().stream()
- .filter(a -> a.getValue().size() == 1)
- .sorted((f, s) -> {
- double one = Double.parseDouble(f.getValue().get(0));
- double two = Double.parseDouble(s.getValue().get(0));
- return Double.compare(two, one);
- })
- .forEach(e ->
- System.out.printf("%s - %.2f%n",
- e.getKey(), Double.parseDouble(e.getValue().get(0))));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement