Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.*;
- public class OntheWaytoAnnapurna {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Map<String, List<String>> map = new HashMap<>();
- String input = scan.nextLine();
- while (!input.equals("END")) {
- String[] tokens = input.split("->");
- String command = tokens[0];
- String store = tokens[1];
- switch (command) {
- case "Add":
- List<String> list = new ArrayList<>(Arrays.asList(tokens[2].split(",")));
- if (list.size() > 1){
- map.putIfAbsent(store, new ArrayList<>());
- for (String s : list) {
- map.get(store).add(s);
- }
- } else {
- String item = tokens[2];
- map.putIfAbsent(store, new ArrayList<>());
- map.get(store).add(item);
- }
- break;
- case "Remove":
- if (map.containsKey(store)){
- map.remove(store);
- }
- break;
- }
- input = scan.nextLine();
- }
- System.out.println("Stores list:");
- map
- .entrySet()
- .stream()
- .sorted()//Help
- .forEach(entry -> {
- System.out.println(entry.getKey());
- entry
- .getValue()
- .stream()
- .sorted((a1, a2) -> a2.compareTo(a1))
- .forEach(s -> System.out.printf("<<%s>>%n", s));
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement