Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class da {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- Map<String, List<Double>> productsMap = new LinkedHashMap<>();
- String[] command = scanner.nextLine().split(" ");
- while (!command[0].equals("buy")) {
- // Rename -> "key" -> product
- String product = command[0];
- double price = Double.parseDouble(command[1]);
- double quantity = Double.parseDouble(command[2]);
- //( Arrays.asList(0.0, 0.0))); ) taq glupost nz kak intelij ti e q predlojil tui kato makes no sense, no moje bi si oburkal //neshto sintakti4no i za tva ti e dal thrashy suggestion, anyway mirishe mi na GPT
- productsMap.putIfAbsent(product, new ArrayList<>());
- productsMap.get(product).set(0, price);
- // Izvedi segashnoto kolichestvo v nova promenliva
- double currentQty = productsMap.get(product).get(1);
- productsMap.get(product).set(1, currentQty + quantity);
- command = scanner.nextLine().split(" ");
- }
- for (Map.Entry<String, List<Double>> pair : productsMap.entrySet()) {
- // Izvedi gi I tiq v promenlivi da e qsno we da go ea
- String team = pair.getKey();
- double price = pair.getValue().get(0);
- double quantity = pair.getValue().get(1);
- // Overall da polzvash <List> det ti pazi kolichestvo i cena ne e ailqk
- double totalPrice = price * quantity;
- System.out.printf("%s -> %.2f\n", team, totalPrice);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement