Advertisement
desislava_topuzakova

02. Hospital Patients

Apr 2nd, 2023
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace HospitalPatients
  6. {
  7. internal class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. List<string> patients = Console.ReadLine() //"Ivan, Peter, Simona, Krasimir, Petya".split(", ")
  13. .Split(", ") //["Ivan", "Peter", "Simona", "Krsimir", "Petya"]
  14. .ToList(); // {"Ivan", "Peter", "Simona", "Krsimir", "Petya"}
  15.  
  16. string command = Console.ReadLine(); //"END OF PATIENTS" или команда
  17. //повтаряме: въвеждаме нова команда
  18. //стоп: команда == "END"
  19. //продължаваме: команда != "END"
  20.  
  21. while (command != "END OF PATIENTS")
  22. {
  23. //валидна команда -> проверка коя е командата
  24. if (command == "Add patient")
  25. {
  26. string name = Console.ReadLine(); //име на пациент за добавяне
  27. patients.Add(name);
  28. }
  29. else if (command == "Add patient on position")
  30. {
  31. string name = Console.ReadLine(); //име на пациент за добавяне
  32. int position = int.Parse(Console.ReadLine()); // позиция на добавяне
  33. patients.Insert(position, name);
  34. }
  35. else if (command == "Remove patient on position")
  36. {
  37. int position = int.Parse(Console.ReadLine());
  38. patients.RemoveAt(position);
  39. }
  40. else if (command == "Remove last patient")
  41. {
  42. patients.RemoveAt(patients.Count - 1);
  43. }
  44. else if (command == "Remove first patient")
  45. {
  46. patients.RemoveAt(0);
  47. }
  48.  
  49. command = Console.ReadLine();
  50. }
  51.  
  52. Console.WriteLine(string.Join(" ", patients));
  53.  
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement