Advertisement
Guest User

Hospital

a guest
Feb 6th, 2018
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace _06.Hospital
  6. {
  7.     class Hospital
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var departments = new Dictionary<string, List<string>>();
  12.             var doctors = new Dictionary<string, List<string>>();
  13.             var line = Console.ReadLine();
  14.  
  15.             while (line != "Output")
  16.             {
  17.                 var tokens = line.Split().ToArray();
  18.                 var dep = tokens[0];
  19.                 var dfn= tokens[1]+" "+ tokens[2];
  20.                 var patient = tokens[3];
  21.                 if (!departments.ContainsKey(dep))
  22.                 {
  23.                     departments[dep] = new List<string>();
  24.                 }
  25.                 departments[dep].Add(patient);
  26.                 if (!doctors.ContainsKey(dfn))
  27.                 {
  28.                     doctors[dfn] = new List<string>();
  29.                 }
  30.                 doctors[dfn].Add(patient);
  31.                 line = Console.ReadLine();
  32.             }
  33.             line = Console.ReadLine().Trim();
  34.             while (line != "End")
  35.             {
  36.                 var token = line.Split().ToArray();
  37.                 if (token.Length == 1)
  38.                 {
  39.                     foreach (var patients in departments[line])
  40.                     {
  41.                         Console.WriteLine(patients);
  42.                     }
  43.                 }
  44.                 else if (int.TryParse(token[1], out int result))
  45.                 {
  46.                     if (int.Parse(token[1]) > 20)
  47.                     {
  48.                         continue;
  49.                     }
  50.                     var patients = departments[token[0]];
  51.                     var room = patients.Skip( 3 * (int.Parse(token[1])-1)).Take(3).OrderBy(p=>p);
  52.                        
  53.                     foreach (var patient in room)
  54.                     {
  55.                         Console.WriteLine(patient);
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     var pat = doctors[line];
  61.                     pat.Sort();
  62.                     foreach (var patient in pat)
  63.                     {
  64.                         Console.WriteLine(patient);
  65.                        
  66.                     }    
  67.                 }
  68.                 line = Console.ReadLine();
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement