Advertisement
krasizorbov

Hospital

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