Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.TreeMap;
- public class Orders {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = input.nextInt();
- input.nextLine();
- Map<String, Map<String, Integer>> mapmap = new LinkedHashMap<>();
- for (int i = 0; i < n; i++) {
- String buffer = input.nextLine();
- String[] container = buffer.split(" ");
- String name = container[0];
- Integer quantity = Integer.parseInt(container[1]);
- String fruit = container[2];
- int tempValue;// da zapazim tuk predishnata stoinost na klu4a i posle da dobavim kam neq oshte plodove
- if (mapmap.get(fruit) == null) { // proverqvame dali golqmata koshnica e prazna purvo
- mapmap.put(fruit, new TreeMap<String, Integer>());
- mapmap.get(fruit).put(name, quantity);
- }
- else {
- if (mapmap.get(fruit).get(name) == null) { // ako ima takav plod v registara , no nqmame takova ime
- mapmap.get(fruit).put(name, quantity);
- }
- else {
- tempValue = mapmap.get(fruit).get(name) + quantity;
- mapmap.get(fruit).put(name, tempValue);
- }
- }
- }
- for (Map.Entry<String, Map<String, Integer>> entries : mapmap.entrySet()) {
- String outputString = (entries.getKey() + ":" + entries.getValue())
- .replace('{', ' ')
- .replace('}', ' ')
- .replace('=', ' ');
- System.out.print(outputString + '\n');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement