Advertisement
svetlyoek

Untitled

May 25th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Hospital
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<int, List<string>>> hospital = new Dictionary<string, Dictionary<int, List<string>>>();
  12. Dictionary<string, List<string>> doctorPatients = new Dictionary<string, List<string>>();
  13. int roomCounter = 1;
  14. string text = string.Empty;
  15.  
  16. while ((text = Console.ReadLine()) != "Output")
  17. {
  18. string[] info = text.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20. string department = info[0];
  21. string doctor = info[1] + " " + info[2];
  22. string patient = info[3];
  23.  
  24. if (!doctorPatients.ContainsKey(doctor))
  25. {
  26. doctorPatients.Add(doctor, new List<string>());
  27. doctorPatients[doctor].Add(patient);
  28. }
  29.  
  30. else
  31. {
  32. doctorPatients[doctor].Add(patient);
  33. }
  34.  
  35. if (!hospital.ContainsKey(department))
  36. {
  37. hospital.Add(department, new Dictionary<int, List<string>>());
  38. hospital[department].Add(roomCounter, new List<string>());
  39. }
  40.  
  41. if(hospital.ContainsKey(department))
  42. {
  43. if(hospital[department].Count==20)
  44. {
  45. continue;
  46. }
  47. else
  48. {
  49. if(hospital[department][roomCounter].Count==3)
  50. {
  51. hospital[department].Add(roomCounter++, new List<string>());
  52. hospital[department][roomCounter++].Add(patient);
  53.  
  54. }
  55. else
  56. {
  57. hospital[department][roomCounter].Add(patient);
  58. }
  59. }
  60. }
  61. else
  62. {
  63. hospital.Add(department, new Dictionary<int, List<string>>());
  64. hospital[department].Add(roomCounter, new List<string>());
  65. hospital[department][roomCounter].Add(patient);
  66. }
  67.  
  68. }
  69.  
  70. string command = string.Empty;
  71.  
  72. while ((command = Console.ReadLine()) != "End")
  73. {
  74. string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  75.  
  76. if (tokens.Length == 1)
  77. {
  78. if (hospital.ContainsKey(tokens[0]))
  79. {
  80. foreach (var kvp in hospital[tokens[0]])
  81. {
  82. foreach (var item in kvp.Value)
  83. {
  84. Console.WriteLine(item);
  85. }
  86. }
  87.  
  88. }
  89. }
  90. else
  91. {
  92. if (doctorPatients.ContainsKey(tokens[0] + " " + tokens[1]))
  93. {
  94. foreach (var kvp in doctorPatients[tokens[0] + " " + tokens[1]].OrderBy(x=>x))
  95. {
  96.  
  97. Console.WriteLine(kvp);
  98. }
  99. }
  100. else
  101. {
  102. if (hospital.ContainsKey(tokens[0]) && hospital[tokens[0]].ContainsKey(int.Parse(tokens[1])))
  103. {
  104. foreach (var kvp in hospital[tokens[0]][int.Parse(tokens[1])].OrderBy(x => x))
  105. {
  106.  
  107. Console.WriteLine(kvp);
  108.  
  109. }
  110. }
  111. }
  112. }
  113.  
  114. }
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement