Advertisement
bullit3189

Hospital

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