Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7.  
  8.  
  9. namespace _04_Hospital
  10.  
  11. {
  12.  
  13.     public class Hospital
  14.  
  15.     {
  16.  
  17.         public const int maxDepartmentCapacity = 20 * 3;
  18.  
  19.  
  20.  
  21.         public static void Main()
  22.  
  23.         {
  24.  
  25.             var patientsByDepartment = new Dictionary<string, HashSet<string>>();
  26.  
  27.             var patientsByDoctor = new Dictionary<string, SortedSet<string>>();
  28.  
  29.  
  30.  
  31.             while (true)
  32.  
  33.             {
  34.  
  35.                 var input = Console.ReadLine();
  36.  
  37.                 if (input == "Output") break;
  38.  
  39.  
  40.  
  41.                 var tokens = input
  42.  
  43.                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  44.  
  45.                             .ToList();
  46.  
  47.                 var department = tokens[0];
  48.  
  49.                 var doctor = tokens[1] + " " + tokens[2];
  50.  
  51.                 var patient = string.Join(" ", tokens.Skip(3));
  52.  
  53.  
  54.  
  55.                 if (!patientsByDepartment.ContainsKey(department))
  56.  
  57.                 {
  58.  
  59.                     patientsByDepartment[department] = new HashSet<string>();
  60.  
  61.                 }
  62.  
  63.                 if (!patientsByDoctor.ContainsKey(doctor))
  64.  
  65.                 {
  66.  
  67.                     patientsByDoctor[doctor] = new SortedSet<string>();
  68.  
  69.                 }
  70.  
  71.                 int departmentCapacity = patientsByDepartment[department].Count();
  72.  
  73.                 if (departmentCapacity < maxDepartmentCapacity)
  74.  
  75.                 {
  76.  
  77.                     patientsByDepartment[department].Add(patient);
  78.  
  79.                     patientsByDoctor[doctor].Add(patient);
  80.  
  81.                 }
  82.  
  83.             }
  84.  
  85.  
  86.  
  87.             SearchHospital(patientsByDepartment, patientsByDoctor);
  88.  
  89.         }
  90.  
  91.  
  92.  
  93.         private static void SearchHospital(Dictionary<string, HashSet<string>> patientsByDepartment, Dictionary<string, SortedSet<string>> patientsByDoctor)
  94.  
  95.         {
  96.  
  97.             while (true)
  98.  
  99.             {
  100.  
  101.                 var input = Console.ReadLine();
  102.  
  103.                 if (input == "End") break;
  104.  
  105.  
  106.  
  107.                 var tokens = input
  108.  
  109.                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  110.  
  111.                             .ToList();
  112.  
  113.                 string department = tokens[0];
  114.  
  115.  
  116.  
  117.                 switch (tokens.Count)
  118.  
  119.                 {
  120.  
  121.                     case 2: // Department Room
  122.  
  123.                         if (patientsByDepartment.ContainsKey(department))
  124.  
  125.                         {
  126.  
  127.                             int room = int.Parse(tokens[1]);
  128.  
  129.                             patientsByDepartment[department]
  130.  
  131.                                 .Skip(3 * (room - 1))
  132.  
  133.                                 .Take(3)
  134.  
  135.                                 .OrderBy(p => p) // alphabetical
  136.  
  137.                                 .ToList()
  138.  
  139.                                 .ForEach(p => Console.WriteLine(p));
  140.  
  141.                         }
  142.  
  143.                         else // Doctor [name surname]
  144.  
  145.                         {
  146.  
  147.                             var doctor = tokens[0] + ' ' + tokens[1];
  148.  
  149.                             if (patientsByDoctor.ContainsKey(doctor))
  150.  
  151.                             {
  152.  
  153.                                 patientsByDoctor[doctor]
  154.  
  155.                                     .ToList()
  156.  
  157.                                     .ForEach(p => Console.WriteLine(p));
  158.  
  159.                             }
  160.  
  161.                         }
  162.  
  163.                         break;
  164.  
  165.                     case 1: // Department
  166.  
  167.                         if (patientsByDepartment.ContainsKey(department))
  168.  
  169.                         {
  170.  
  171.                             patientsByDepartment[department]
  172.  
  173.                                 .ToList() // order of appearance
  174.  
  175.                                 .ForEach(p => Console.WriteLine(p));
  176.  
  177.                         }
  178.  
  179.                         break;
  180.  
  181.                     default: break;
  182.  
  183.                 }
  184.  
  185.             }
  186.  
  187.         }
  188.  
  189.     }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement