fbinnzhivko

04. Firefighters

Mar 16th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int savedKids = 0;
  7.         int savedAdults = 0;
  8.         int savedSeniors = 0;
  9.  
  10.         int numberOfFighers = int.Parse(Console.ReadLine());
  11.         string inputLine = Console.ReadLine();
  12.  
  13.         while (inputLine != "rain")
  14.         {
  15.             int remainingFirefighters = numberOfFighers;
  16.             int priorityPerson = 1;
  17.  
  18.             while (remainingFirefighters > 0 && priorityPerson <= 3)
  19.             {
  20.                 foreach (char t in inputLine)
  21.                 {
  22.                     if (remainingFirefighters <= 0) { break; }
  23.                     switch (priorityPerson)
  24.                     {
  25.                         case 1: if (t == 'K') { savedKids++; remainingFirefighters--; } break;
  26.                         case 2: if (t == 'A') { savedAdults++; remainingFirefighters--; } break;
  27.                         case 3: if (t == 'S') { savedSeniors++; remainingFirefighters--; } break;
  28.                     }
  29.                 }
  30.                 priorityPerson++;
  31.             }
  32.             inputLine = Console.ReadLine();
  33.         }
  34.         Console.WriteLine("Kids: {0}", savedKids);
  35.         Console.WriteLine("Adults: {0}", savedAdults);
  36.         Console.WriteLine("Seniors: {0}", savedSeniors);
  37.     }
  38. }
Add Comment
Please, Sign In to add comment