Advertisement
gadjov

Untitled

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