Advertisement
simeon3000

Hospital

Feb 6th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1. namespace P04.Hospital
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     class Hospital
  8.     {
  9.         static void Main()
  10.         {
  11.             var patients = new List<Patient>();
  12.            
  13.             string input;
  14.             while ((input = Console.ReadLine()) != "Output")
  15.             {
  16.                 string[] inputArgs = input.Split();
  17.                 string departmentName = inputArgs[0];
  18.                 string docFisrtName = inputArgs[1];
  19.                 string docLastName = inputArgs[2];
  20.                 string doctorName = $"{docFisrtName} {docLastName}";
  21.                 string patientName = inputArgs[3];
  22.  
  23.                 Patient patient = new Patient(departmentName, doctorName, patientName);
  24.                
  25.                 patients.Add(patient);
  26.             }
  27.  
  28.             string output;
  29.             while ((output = Console.ReadLine()) != "End")
  30.             {
  31.                 string[] outputArgs = output.Split();
  32.                 if (patients.Any(p => p.Department == outputArgs[0]))
  33.                 {
  34.                     if (outputArgs.Length == 1)
  35.                     {
  36.                         foreach (var patient in patients
  37.                             .Where(p => p.Department == output))
  38.                         {
  39.                             Print(patient);
  40.                         }
  41.                     }
  42.                     else
  43.                     {
  44.                         var departmentPatients = new List<Patient>();
  45.                         int roomNumber = int.Parse(outputArgs[1]);
  46.  
  47.                         foreach (var patient in patients
  48.                             .Where(p => p.Department == outputArgs[0]))
  49.                         {
  50.                             departmentPatients.Add(patient);
  51.                         }
  52.  
  53.                         var result = new List<Patient>();
  54.                         for (int i = 0; i < departmentPatients.Count; i++)
  55.                         {
  56.                             if (Math.Ceiling((i + 1) /3.0) == roomNumber)
  57.                             {
  58.                                 var patient = departmentPatients[i];
  59.                                 result.Add(patient);
  60.                             }
  61.                         }
  62.  
  63.                         foreach (var patient in result.OrderBy(p => p.Name))
  64.                         {
  65.                             Print(patient);
  66.                         }
  67.                     }                    
  68.                 }
  69.  
  70.                 else
  71.                 {
  72.                     foreach (var patient in patients
  73.                         .Where(p => p.Doctor == output.TrimEnd())
  74.                         .OrderBy(p => p.Name))
  75.                     {
  76.                         Print(patient);
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.  
  82.         private static void Print (Patient patient)
  83.         {
  84.             Console.WriteLine(patient.Name);
  85.         }
  86.     }
  87.  
  88.     public class Patient
  89.     {
  90.         public Patient(string department, string doctor, string name)
  91.         {
  92.             this.Department = department;
  93.             this.Doctor = doctor;
  94.             this.Name = name;
  95.         }
  96.  
  97.         public string Department { get; set; }
  98.         public string Doctor { get; set; }
  99.         public string Name { get; set; }
  100.     }      
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement