Advertisement
Guest User

Firefighters

a guest
Oct 19th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Problem4
  8. {
  9.     class Problem4
  10.     {
  11.         static void Main()
  12.         {
  13.             int firefighters = int.Parse(Console.ReadLine());
  14.             int counterKids = 0;
  15.             int counterAdults = 0;
  16.             int counterSenior = 0;
  17.             int counterFireFighters = firefighters;
  18.  
  19.             string command = Console.ReadLine();
  20.  
  21.             while (command != "rain")
  22.             {
  23.                
  24.  
  25.                     for (int i = 0; i < command.Length; i++)
  26.                     {
  27.                         if (command[i] == 'K' && counterFireFighters > 0)
  28.                         {
  29.                             if (counterFireFighters < 0)
  30.                             {
  31.                                 break;
  32.                             }
  33.                             counterKids++;
  34.                             counterFireFighters--;
  35.                             command = command.Remove(i, 1);
  36.                             i--;
  37.  
  38.                         }
  39.                     }
  40.                  
  41.  
  42.                     for (int i = 0; i < command.Length; i++)
  43.                     {
  44.                         if (command[i] == 'A' && counterFireFighters > 0)
  45.                         {
  46.                             if (counterFireFighters < 0)
  47.                             {
  48.                                 break;
  49.                             }
  50.                             counterAdults++;
  51.                             counterFireFighters--;
  52.                             command = command.Remove(i, 1);
  53.                             i--;
  54.  
  55.                         }
  56.                     }
  57.  
  58.  
  59.                     for (int i = 0; i < command.Length; i++)
  60.                     {
  61.                         if (command[i] == 'S' && counterFireFighters > 0)
  62.                         {
  63.                             if (counterFireFighters < 0)
  64.                             {
  65.                                 break;
  66.                             }
  67.                             counterSenior++;
  68.                             counterFireFighters--;
  69.                             command = command.Remove(i, 1);
  70.                             i--;
  71.  
  72.                         }
  73.                     }
  74.  
  75.  
  76.                 counterFireFighters = firefighters;
  77.  
  78.                 command = Console.ReadLine();
  79.  
  80.             }
  81.  
  82.             Console.WriteLine("Kids: {0}",counterKids);
  83.             Console.WriteLine("Adults: {0}",counterAdults);
  84.             Console.WriteLine("Seniors: {0}",counterSenior);
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement