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);
- System.out.println("OK");
- break;
- case "Insert":
- int position = Integer.parseInt(inputCommand[1]);
- name = inputCommand[2];
- if (position > queuePeople.size()) {
- System.out.println("Error");
- } else if (position <= queuePeople.size() - 1) {
- queuePeople.add(position, name);
- System.out.println("OK");
- } else if (position == queuePeople.size()) {
- queuePeople.add(name);
- System.out.println("OK");
- }
- break;
- case "Find":
- name = inputCommand[1];
- int counter = 0;
- for (int i = 0; i < queuePeople.size(); i++) {
- if (queuePeople.get(i).equals(name)) {
- counter++;
- }
- }
- System.out.println(counter);
- break;
- case "Examine":
- int count = Integer.parseInt(inputCommand[1]);
- if (count <= queuePeople.size()) {
- while (count > 0) {
- System.out.print(queuePeople.remove(0) + " ");
- count--;
- }
- System.out.println();
- } else {
- System.out.println("Error");
- }
- 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