Advertisement
svetlyoek

Untitled

May 26th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 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.  
  36. if(hospital.ContainsKey(department))
  37. {
  38. if(hospital[department].Count==20)
  39. {
  40. continue;
  41. }
  42. else
  43. {
  44. if(hospital[department][roomCounter].Count==3)
  45. {
  46. hospital[department].Add(roomCounter++, new List<string>());
  47. hospital[department][roomCounter++].Add(patient);
  48.  
  49. }
  50. else
  51. {
  52. hospital[department][roomCounter].Add(patient);
  53. }
  54. }
  55. }
  56. else
  57. {
  58. hospital.Add(department, new Dictionary<int, List<string>>());
  59. hospital[department].Add(roomCounter, new List<string>());
  60. hospital[department][roomCounter].Add(patient);
  61. }
  62.  
  63. }
  64.  
  65. string command = string.Empty;
  66.  
  67. while ((command = Console.ReadLine().Trim()) != "End")
  68. {
  69. string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  70.  
  71. if (tokens.Length == 1)
  72. {
  73. if (hospital.ContainsKey(tokens[0]))
  74. {
  75. foreach (var dep in hospital[tokens[0]])
  76. {
  77.  
  78. foreach (var patient in dep.Value.Where(x => x != null))
  79. {
  80. if(patient==null)
  81. {
  82. break;
  83. }
  84. Console.WriteLine(patient);
  85. }
  86. }
  87.  
  88. }
  89. }
  90. else
  91. {
  92.  
  93. if (doctorPatients.ContainsKey(tokens[0] + " " + tokens[1]))
  94. {
  95. foreach (var kvp in doctorPatients[tokens[0] + " " + tokens[1]].OrderBy(x=>x))
  96. {
  97.  
  98. Console.WriteLine(kvp);
  99. }
  100. }
  101. else
  102. {
  103. if (hospital.ContainsKey(tokens[0]) && hospital[tokens[0]].ContainsKey(int.Parse(tokens[1])))
  104. {
  105. foreach (var kvp in hospital[tokens[0]][int.Parse(tokens[1])].Where(x=>x!=null).OrderBy(x => x))
  106. {
  107. if(kvp==null)
  108. {
  109. break;
  110. }
  111. Console.WriteLine(kvp);
  112.  
  113. }
  114. }
  115. }
  116. }
  117.  
  118. }
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement