medon3

Untitled

Jun 15th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class DoctorsOffice {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner sc = new Scanner(System.in);
  8. String[] inputCommand = sc.nextLine().split(" ");
  9.  
  10. List<String> queuePeople = new ArrayList<>();
  11. Map<String, Integer> names = new HashMap<>();
  12.  
  13. while (!inputCommand[0].equals("Еnd")) {
  14. switch (inputCommand[0]) {
  15. case "Append":
  16. String name = inputCommand[1];
  17. queuePeople.add(name);
  18. System.out.println("OK");
  19. break;
  20. case "Insert":
  21. int position = Integer.parseInt(inputCommand[1]);
  22. name = inputCommand[2];
  23. if (position > queuePeople.size()) {
  24. System.out.println("Error");
  25. } else if (position <= queuePeople.size() - 1) {
  26. queuePeople.add(position, name);
  27. System.out.println("OK");
  28. } else if (position == queuePeople.size()) {
  29. queuePeople.add(name);
  30. System.out.println("OK");
  31. }
  32. break;
  33. case "Find":
  34. name = inputCommand[1];
  35. int counter = 0;
  36. for (int i = 0; i < queuePeople.size(); i++) {
  37. if (queuePeople.get(i).equals(name)) {
  38. counter++;
  39. }
  40. }
  41. System.out.println(counter);
  42. break;
  43. case "Examine":
  44. int count = Integer.parseInt(inputCommand[1]);
  45.  
  46. if (count <= queuePeople.size()) {
  47. while (count > 0) {
  48. System.out.print(queuePeople.remove(0) + " ");
  49. count--;
  50. }
  51. System.out.println();
  52. } else {
  53. System.out.println("Error");
  54. }
  55.  
  56. break;
  57. }
  58.  
  59. inputCommand = sc.nextLine().split(" ");
  60. }
  61.  
  62. // for (String str : queuePeople) {
  63. // if (names.containsKey(str)) {
  64. // int currentCount = names.get(str);
  65. // names.put(str, currentCount + 1);
  66. // } else {
  67. // names.put(str, 1);
  68. // }
  69. }
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment