miroslavbstoyanov

Untitled

Feb 5th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04.Hospital
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = "";
  14. var dict = new Dictionary<string, Dictionary<string, string>>();
  15.  
  16. while ((input = Console.ReadLine()) != "Output")
  17. {
  18. string[] splitInput = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  19. string department = splitInput[0];
  20. string doctor = $"{splitInput[1]} {splitInput[2]}";
  21. string patient = splitInput[3];
  22.  
  23. if (!dict.ContainsKey(department))
  24. {
  25. dict.Add(department, new Dictionary<string, string>());
  26. dict[department].Add(patient, doctor);
  27. }
  28. else if(dict[department].Count() < 60)
  29. {
  30. dict[department].Add(patient, doctor);
  31. }
  32. }
  33.  
  34. string secondInput = "";
  35.  
  36. while ((secondInput = Console.ReadLine()) != "End")
  37. {
  38. string[] output = secondInput.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  39.  
  40. if (output.Length == 1)
  41. {
  42. foreach (var item in dict[output[0]])
  43. {
  44. Console.WriteLine(item.Key);
  45. }
  46. }
  47. else if (dict.ContainsKey(output[0]))
  48. {
  49. int index = int.Parse(output[1]);
  50. int endIndex = index * 3;
  51. int startIndex = endIndex - 3;
  52. int count = 0;
  53. List<string> list = new List<string>();
  54. foreach (var item in dict[output[0]])
  55. {
  56.  
  57. if (count >= startIndex && count < endIndex)
  58. {
  59. list.Add(item.Key);
  60. }
  61. count++;
  62. }
  63.  
  64. foreach (var item in list.OrderBy(x => x))
  65. {
  66. Console.WriteLine(item);
  67. }
  68. }
  69. else
  70. {
  71. string doctor = $"{output[0]} {output[1]}";
  72. List<string> listofPatients = new List<string>();
  73.  
  74. foreach (var item in dict)
  75. {
  76. foreach (var s in item.Value)
  77. {
  78. string doctorValue = s.Value;
  79. if (doctorValue == doctor)
  80. {
  81. listofPatients.Add(s.Key);
  82. }
  83. }
  84. }
  85.  
  86. foreach (var item in listofPatients.OrderBy(x => x))
  87. {
  88. Console.WriteLine(item);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment