Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _04.Hospital
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- public class StartUp
- {
- public static void Main()
- {
- Dictionary<string, List<string>> doctorsAndPatients = new Dictionary<string, List<string>>();
- Dictionary<string, Dictionary<int, List<string>>> deparmentsAndRooms = new Dictionary<string, Dictionary<int, List<string>>>();
- string inputLine;
- while ((inputLine = Console.ReadLine()) != "Output")
- {
- string[] tokens = SplitString(inputLine);
- string department = tokens[0];
- string doctorName = tokens[1] + " " + tokens[2];
- string patientName = tokens[3];
- //subscribing the patient to the doctor
- if (!doctorsAndPatients.ContainsKey(doctorName))
- {
- doctorsAndPatients[doctorName] = new List<string>();
- }
- doctorsAndPatients[doctorName].Add(patientName);
- //END OF SUBSCRIPTION
- //Place the patient in a room
- if (!deparmentsAndRooms.ContainsKey(department))
- {
- deparmentsAndRooms[department] = new Dictionary<int, List<string>>();
- }
- int roomIndex = 1;
- if (deparmentsAndRooms[department].Count > 0)
- {
- roomIndex = deparmentsAndRooms[department].Keys.Last();
- }
- if (!deparmentsAndRooms[department].ContainsKey(roomIndex))
- {
- deparmentsAndRooms[department][roomIndex] = new List<string>();
- }
- if (deparmentsAndRooms[department][roomIndex].Count < 3)
- {
- deparmentsAndRooms[department][roomIndex].Add(patientName);
- }
- else
- {
- roomIndex++;
- if (roomIndex > 20)
- {
- continue;
- }
- deparmentsAndRooms[department][roomIndex] = new List<string>
- {
- patientName
- };
- }
- }
- StringBuilder result = new StringBuilder();
- while ((inputLine = Console.ReadLine()) != "End")
- {
- string[] tokens = SplitString(inputLine);
- if (tokens.Length == 2)
- {
- int roomIndex;
- if (int.TryParse(tokens[1], out roomIndex))
- {
- string department = tokens[0];
- List<string> patients = deparmentsAndRooms[department][roomIndex];
- foreach (string patient in patients.OrderBy(n => n))
- {
- result.AppendLine(patient);
- }
- }
- else
- {
- string doctorName = tokens[0] + " " + tokens[1];
- List<string> patients = doctorsAndPatients[doctorName];
- foreach (string patient in patients.OrderBy(n => n))
- {
- result.AppendLine(patient);
- }
- }
- }
- else
- {
- string department = tokens[0];
- foreach (KeyValuePair<int, List<string>> kvp in deparmentsAndRooms[department])
- {
- foreach (string patient in kvp.Value)
- {
- result.AppendLine(patient);
- }
- }
- }
- }
- Console.Write(result);
- }
- private static string[] SplitString(string stringToSplit)
- {
- return stringToSplit.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement