Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.Hospital
- {
- public class Program
- {
- public static void Main()
- {
- var departmentPatients = new Dictionary<string, List<string>>();
- var departmentRoomsBeds = new Dictionary<string, Dictionary<int, List<string>>>();
- var doctorPatients = new Dictionary<string, List<string>>();
- while (true)
- {
- var input = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (input[0] == "Output")
- {
- break;
- }
- string department = input[0];
- string doctor = input[1] + " " + input[2];
- string patient = input[3];
- if (!departmentRoomsBeds.ContainsKey(department))
- {
- departmentRoomsBeds.Add(department, new Dictionary<int, List<string>>());
- }
- foreach (var kvp in departmentRoomsBeds)
- {
- string depart = kvp.Key;
- var roomsAndBeds = kvp.Value;
- if (depart == department)
- {
- for (int i = 1; i <= 20; i++)
- {
- if (roomsAndBeds.ContainsKey(i) && roomsAndBeds[i].Count < 3)
- {
- departmentRoomsBeds[depart][i].Add(patient);
- break;
- }
- {
- bool doesContain = roomsAndBeds.ContainsKey(i);
- bool isFull = roomsAndBeds.Values.Count == 3;
- if (doesContain == false)
- {
- roomsAndBeds.Add(i, new List<string>());
- departmentRoomsBeds[depart][i].Add(patient);
- break;
- }
- if (isFull)
- {
- continue;
- }
- }
- }
- }
- }
- if (!departmentPatients.ContainsKey(department))
- {
- departmentPatients.Add(department, new List<string>());
- }
- departmentPatients[department].Add(patient);
- if (!doctorPatients.ContainsKey(doctor))
- {
- doctorPatients.Add(doctor, new List<string>());
- }
- doctorPatients[doctor].Add(patient);
- }
- while (true)
- {
- var command = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (command[0] == "End")
- {
- return;
- }
- if (command.Length == 1)
- {
- foreach (var kvp in departmentPatients)
- {
- if (kvp.Key == command[0])
- {
- foreach (var patient in kvp.Value)
- {
- Console.WriteLine(patient);
- }
- }
- }
- }
- else if (departmentRoomsBeds.ContainsKey(command[0]) && char.IsDigit(command[1][0]))
- {
- foreach (var kvp in departmentRoomsBeds)
- {
- if (kvp.Key == command[0])
- {
- foreach (var innerKvp in kvp.Value)
- {
- if (innerKvp.Key == int.Parse(command[1]))
- {
- foreach (var patient in innerKvp.Value.OrderBy(x => x))
- {
- Console.WriteLine(patient);
- }
- }
- }
- }
- }
- }
- else if (doctorPatients.ContainsKey(command[0] + " " + command[1]))
- {
- foreach (var kvp in doctorPatients)
- {
- if (kvp.Key == command[0] + " " + command[1])
- {
- foreach (var patient in kvp.Value.OrderBy(x => x))
- {
- Console.WriteLine(patient);
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement