Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class DoctorsOffice {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] inputCommand = sc.nextLine().split(" ");
- List<String> queuePeople = new ArrayList<>();
- Map<String, Integer> names = new HashMap<>();
- while (!inputCommand[0].equals("Еnd")) {
- switch (inputCommand[0]) {
- case "Append":
- String name = inputCommand[1];
- queuePeople.add(name);
- names.putIfAbsent(inputCommand[1], 0);
- names.replace(inputCommand[1], names.get(inputCommand[1]) + 1);
- System.out.println("OK");
- break;
- case "Insert":
- int position = Integer.parseInt(inputCommand[1]);
- name = inputCommand[2];
- if(position>queuePeople.size()){
- System.out.println("Error");
- break;
- }
- queuePeople.add(position, name);
- names.putIfAbsent(name, 0);
- names.replace(name, names.get(inputCommand[2]) + 1);
- System.out.println("OK");
- break;
- case "Find":
- name = inputCommand[1];
- if(names.containsKey(name)){
- System.out.println(names.get(name));
- break;
- }
- System.out.println(0);
- break;
- case "Examine":
- int count = Integer.parseInt(inputCommand[1]);
- if (count > queuePeople.size()) {
- System.out.println("Error");
- break;
- }
- Stack<String> examineStack = new Stack<>();
- for (int i = 0; i < count; i++) {
- examineStack.push(queuePeople.remove(0));
- names.replace(examineStack.peek(),
- names.get(examineStack.peek()) - 1);
- }
- for (String person : examineStack) {
- System.out.print(person + " ");
- }
- System.out.println();
- break;
- }
- inputCommand = sc.nextLine().split(" ");
- }
- // for (String str : queuePeople) {
- // if (names.containsKey(str)) {
- // int currentCount = names.get(str);
- // names.put(str, currentCount + 1);
- // } else {
- // names.put(str, 1);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement