Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace P04.Hospital
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Hospital
- {
- static void Main()
- {
- var patients = new List<Patient>();
- string input;
- while ((input = Console.ReadLine()) != "Output")
- {
- string[] inputArgs = input.Split();
- string departmentName = inputArgs[0];
- string docFisrtName = inputArgs[1];
- string docLastName = inputArgs[2];
- string doctorName = $"{docFisrtName} {docLastName}";
- string patientName = inputArgs[3];
- Patient patient = new Patient(departmentName, doctorName, patientName);
- patients.Add(patient);
- }
- string output;
- while ((output = Console.ReadLine()) != "End")
- {
- string[] outputArgs = output.Split();
- if (patients.Any(p => p.Department == outputArgs[0]))
- {
- if (outputArgs.Length == 1)
- {
- foreach (var patient in patients
- .Where(p => p.Department == output))
- {
- Print(patient);
- }
- }
- else
- {
- var departmentPatients = new List<Patient>();
- int roomNumber = int.Parse(outputArgs[1]);
- foreach (var patient in patients
- .Where(p => p.Department == outputArgs[0]))
- {
- departmentPatients.Add(patient);
- }
- var result = new List<Patient>();
- for (int i = 0; i < departmentPatients.Count; i++)
- {
- if (Math.Ceiling((i + 1) /3.0) == roomNumber)
- {
- var patient = departmentPatients[i];
- result.Add(patient);
- }
- }
- foreach (var patient in result.OrderBy(p => p.Name))
- {
- Print(patient);
- }
- }
- }
- else
- {
- foreach (var patient in patients
- .Where(p => p.Doctor == output.TrimEnd())
- .OrderBy(p => p.Name))
- {
- Print(patient);
- }
- }
- }
- }
- private static void Print (Patient patient)
- {
- Console.WriteLine(patient.Name);
- }
- }
- public class Patient
- {
- public Patient(string department, string doctor, string name)
- {
- this.Department = department;
- this.Doctor = doctor;
- this.Name = name;
- }
- public string Department { get; set; }
- public string Doctor { get; set; }
- public string Name { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement