Advertisement
krasizorbov

Hospital Working

May 27th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Hospital
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var hospital = new Dictionary<string, Dictionary<int, List<string>>>();
  12.             var doctorPatients = new Dictionary<string, List<string>>();
  13.            
  14.             string text = string.Empty;
  15.  
  16.             while ((text = Console.ReadLine()) != "Output")
  17.             {
  18.                 string[] info = text.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20.                 string department = info[0];
  21.                 string doctor = info[1] + " " + info[2];
  22.                 string patient = info[3];
  23.  
  24.                 if (!doctorPatients.ContainsKey(doctor))
  25.                 {
  26.                     doctorPatients.Add(doctor, new List<string>());
  27.                 }
  28.  
  29.                 doctorPatients[doctor].Add(patient);
  30.  
  31.                 if (hospital.ContainsKey(department))
  32.                 {
  33.                     if (hospital[department].Values.Count > 20)
  34.                     {
  35.                         continue;
  36.                     }
  37.                     else
  38.                     {
  39.                         if (hospital[department][hospital[department].Values.Count].Count == 3)
  40.                         {
  41.                             hospital[department].Add(hospital[department].Values.Count + 1, new List<string>());
  42.                             hospital[department][hospital[department].Values.Count].Add(patient);
  43.                         }
  44.                         else
  45.                         {
  46.                             hospital[department][hospital[department].Values.Count].Add(patient);
  47.                         }
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     hospital.Add(department, new Dictionary<int, List<string>>());
  53.                     hospital[department].Add(1, new List<string>());
  54.                     hospital[department][1].Add(patient);
  55.                 }
  56.  
  57.             }
  58.  
  59.             string command = string.Empty;
  60.  
  61.             while ((command = Console.ReadLine().Trim()) != "End")
  62.             {
  63.                 string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  64.  
  65.                 if (tokens.Length == 1)
  66.                 {
  67.                     if (hospital.ContainsKey(tokens[0]))
  68.                     {
  69.                         foreach (var dep in hospital[tokens[0]])
  70.                         {
  71.                             foreach (var patient in dep.Value)
  72.                             {
  73.                                 Console.WriteLine(patient);
  74.                             }
  75.                         }
  76.  
  77.                     }
  78.                 }
  79.                 else
  80.                 {
  81.  
  82.                     if (doctorPatients.ContainsKey(tokens[0] + " " + tokens[1]))
  83.                     {
  84.                         foreach (var kvp in doctorPatients[tokens[0] + " " + tokens[1]].OrderBy(x => x))
  85.                         {
  86.  
  87.                             Console.WriteLine(kvp);
  88.                         }
  89.                     }
  90.                     else
  91.                     {
  92.                         if (hospital.ContainsKey(tokens[0]) && hospital[tokens[0]].ContainsKey(int.Parse(tokens[1])))
  93.                         {
  94.                             foreach (var kvp in hospital[tokens[0]][int.Parse(tokens[1])].OrderBy(x => x))
  95.                             {
  96.                                 Console.WriteLine(kvp);
  97.                             }
  98.                         }
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement