Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.Hospital
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             var departmentPatients = new Dictionary<string, List<string>>();
  12.             var departmentRoomsBeds = new Dictionary<string, Dictionary<int, List<string>>>();
  13.             var doctorPatients = new Dictionary<string, List<string>>();
  14.  
  15.             while (true)
  16.             {
  17.                 var input = Console.ReadLine()
  18.                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToArray();
  20.  
  21.                 if (input[0] == "Output")
  22.                 {
  23.                     break;
  24.                 }
  25.  
  26.                 string department = input[0];
  27.                 string doctor = input[1] + " " + input[2];
  28.                 string patient = input[3];
  29.  
  30.                 if (!departmentRoomsBeds.ContainsKey(department))
  31.                 {
  32.                     departmentRoomsBeds.Add(department, new Dictionary<int, List<string>>());
  33.                 }
  34.                 foreach (var kvp in departmentRoomsBeds)
  35.                 {
  36.                     string depart = kvp.Key;
  37.                     var roomsAndBeds = kvp.Value;
  38.                     if (depart == department)
  39.                     {
  40.                         for (int i = 1; i <= 20; i++)
  41.                         {
  42.                             if (roomsAndBeds.ContainsKey(i) && roomsAndBeds[i].Count < 3)
  43.                             {
  44.                                 departmentRoomsBeds[depart][i].Add(patient);
  45.                                 break;
  46.                             }
  47.                             {
  48.                                 bool doesContain = roomsAndBeds.ContainsKey(i);
  49.                                 bool isFull = roomsAndBeds.Values.Count == 3;
  50.                                 if (doesContain == false)
  51.                                 {
  52.                                     roomsAndBeds.Add(i, new List<string>());
  53.                                     departmentRoomsBeds[depart][i].Add(patient);
  54.                                     break;
  55.                                 }
  56.                                 if (isFull)
  57.                                 {
  58.                                     continue;
  59.                                 }
  60.                             }
  61.                         }
  62.                     }
  63.                    
  64.                 }
  65.  
  66.                 if (!departmentPatients.ContainsKey(department))
  67.                 {
  68.                     departmentPatients.Add(department, new List<string>());
  69.                 }
  70.                 departmentPatients[department].Add(patient);
  71.  
  72.                 if (!doctorPatients.ContainsKey(doctor))
  73.                 {
  74.                     doctorPatients.Add(doctor, new List<string>());
  75.                 }
  76.                 doctorPatients[doctor].Add(patient);
  77.             }
  78.  
  79.             while (true)
  80.             {
  81.                 var command = Console.ReadLine()
  82.                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  83.                     .ToArray();
  84.  
  85.                 if (command[0] == "End")
  86.                 {
  87.                     return;
  88.                 }
  89.                 if (command.Length == 1)
  90.                 {
  91.                     foreach (var kvp in departmentPatients)
  92.                     {
  93.                         if (kvp.Key == command[0])
  94.                         {
  95.                             foreach (var patient in kvp.Value)
  96.                             {
  97.  
  98.                                 Console.WriteLine(patient);
  99.                             }
  100.                         }
  101.                     }
  102.                 }
  103.                  else if (departmentRoomsBeds.ContainsKey(command[0]) && char.IsDigit(command[1][0]))
  104.                 {
  105.                     foreach (var kvp in departmentRoomsBeds)
  106.                     {
  107.                         if (kvp.Key == command[0])
  108.                         {
  109.                             foreach (var innerKvp in kvp.Value)
  110.                             {
  111.                                 if (innerKvp.Key == int.Parse(command[1]))
  112.                                 {
  113.                                     foreach (var patient in innerKvp.Value.OrderBy(x => x))
  114.                                     {
  115.                                         Console.WriteLine(patient);
  116.                                     }
  117.                                 }
  118.                             }
  119.                         }
  120.                     }
  121.                 }
  122.                  else if (doctorPatients.ContainsKey(command[0] + " " + command[1]))
  123.                 {
  124.                     foreach (var kvp in doctorPatients)
  125.                     {
  126.                         if (kvp.Key == command[0] + " " + command[1])
  127.                         {
  128.                             foreach (var patient in kvp.Value.OrderBy(x => x))
  129.                             {
  130.                                 Console.WriteLine(patient);
  131.                             }
  132.                         }
  133.                     }
  134.                 }
  135.             }
  136.         }
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement