Advertisement
Danny_Berova

04.Hospital

Feb 5th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Hospital
  6. {
  7.     public class Hospital
  8.     {
  9.         public static void Main()
  10.         {
  11.             var departments = new Dictionary<string, List<string>>();
  12.             var doctors = new Dictionary<string, List<string>>();
  13.  
  14.             var inputLine = Console.ReadLine();
  15.  
  16.  
  17.             while (inputLine != "Output")
  18.             {
  19.                 var inputTokens = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21.                 if (inputTokens.Length == 4)
  22.                 {
  23.                     var departmentName = inputTokens[0];
  24.                     if (departmentName.Length > 100)
  25.                     {
  26.                         continue;
  27.                     }
  28.                     var doctorsFirstName = inputTokens[1];
  29.                     var doctorsLastName = inputTokens[2];
  30.                     var docFullName = $"{doctorsFirstName} {doctorsLastName}";
  31.                     var patient = inputTokens[3];
  32.  
  33.                     if (!departments.ContainsKey(departmentName))
  34.                     {
  35.                         departments[departmentName] = new List<string>();
  36.                     }
  37.                     if (doctorsFirstName.Length <= 20 && doctorsLastName.Length <= 20 && !doctors.ContainsKey(docFullName))
  38.                     {
  39.                         doctors[docFullName] = new List<string>();
  40.                     }
  41.  
  42.                     if (departments[departmentName].Count < 60)
  43.                     {
  44.                         departments[departmentName].Add(patient);
  45.                     }
  46.  
  47.                     doctors[docFullName].Add(patient);
  48.  
  49.                 }
  50.  
  51.                 inputLine = Console.ReadLine();
  52.             }
  53.  
  54.             inputLine = Console.ReadLine();
  55.  
  56.             while (inputLine != "End")
  57.             {
  58.                 var tokensToOutput = inputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  59.  
  60.                 if (tokensToOutput.Length == 1)
  61.                 {
  62.                     Console.WriteLine(string.Join(Environment.NewLine, departments[inputLine]));
  63.                 }
  64.                 else
  65.                 {
  66.                     if (doctors.ContainsKey(inputLine.Trim()))
  67.                     {
  68.                         var doc = inputLine.Trim();
  69.                         var patients = doctors[doc].OrderBy(x => x);
  70.                         Console.WriteLine(string.Join(Environment.NewLine, patients));
  71.                     }
  72.                     else
  73.                     {
  74.                         string department = tokensToOutput[0];
  75.                         int room = int.Parse(tokensToOutput[1]);
  76.  
  77.                         if (room <= 20 && departments[department].Count > (room * 3) - 2)
  78.                         {
  79.                             var patientsInRoom = departments[department].Skip(room * 3 - 3).Take(3).OrderBy(x => x);
  80.                             Console.WriteLine(string.Join(Environment.NewLine, patientsInRoom));
  81.                         }
  82.                     }
  83.                 }
  84.  
  85.                 inputLine = Console.ReadLine();
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement