Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P04_Hospital
  6. {
  7.     public class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             Dictionary<string, List<string>> doktori = new Dictionary<string, List<string>>();
  12.             Dictionary<string, List<List<string>>> departments = new Dictionary<string, List<List<string>>>();
  13.  
  14.  
  15.             string command = Console.ReadLine();
  16.             while (command != "Output")
  17.             {
  18.                 string[] jetoni = command.Split();
  19.                 var departament = jetoni[0];
  20.                 var purvoIme = jetoni[1];
  21.                 var vtoroIme = jetoni[2];
  22.                 var pacient = jetoni[3];
  23.                 var cqloIme = purvoIme + vtoroIme;
  24.  
  25.                 if (!doktori.ContainsKey(purvoIme + vtoroIme))
  26.                 {
  27.                     doktori[cqloIme] = new List<string>();
  28.                 }
  29.                 if (!departments.ContainsKey(departament))
  30.                 {
  31.                     departments[departament] = new List<List<string>>();
  32.                     for (int stai = 0; stai < 20; stai++)
  33.                     {
  34.                         departments[departament].Add(new List<string>());
  35.                     }
  36.                 }
  37.  
  38.                 bool imaMqsto = departments[departament].SelectMany(x => x).Count() < 60;
  39.                 if (imaMqsto)
  40.                 {
  41.                     int staq = 0;
  42.                     doktori[cqloIme].Add(pacient);
  43.                     for (int st = 0; st < departments[departament].Count; st++)
  44.                     {
  45.                         if (departments[departament][st].Count < 3)
  46.                         {
  47.                             staq = st;
  48.                             break;
  49.                         }
  50.                     }
  51.                     departments[departament][staq].Add(pacient);
  52.                 }
  53.  
  54.                 command = Console.ReadLine();
  55.             }
  56.  
  57.             command = Console.ReadLine();
  58.  
  59.             while (command != "End")
  60.             {
  61.                 string[] args = command.Split();
  62.  
  63.                 if (args.Length == 1)
  64.                 {
  65.                     Console.WriteLine(string.Join("\n", departments[args[0]].Where(x => x.Count > 0).SelectMany(x => x)));
  66.                 }
  67.                 else if (args.Length == 2 && int.TryParse(args[1], out int staq))
  68.                 {
  69.                     Console.WriteLine(string.Join("\n", departments[args[0]][staq - 1].OrderBy(x => x)));
  70.                 }
  71.                 else
  72.                 {
  73.                     Console.WriteLine(string.Join("\n", doktori[args[0] + args[1]].OrderBy(x => x)));
  74.                 }
  75.                 command = Console.ReadLine();
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement