Advertisement
sylviapsh

Advertising letters

Dec 27th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. class Advertising
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //How many times you could write the word TAT with the letters given on the 3 input lines.
  8.  
  9.     string input1 = Console.ReadLine(),
  10.            input2 = Console.ReadLine(),
  11.            input3 = Console.ReadLine();
  12.  
  13.     string allInput = input1 + input2 + input3;
  14.     int counterT = 0,
  15.         counterA = 0,
  16.         counterAdvertisments = 0;
  17.  
  18.     foreach (char item in allInput)
  19.     {
  20.       if (item == 'T')
  21.       {
  22.         counterT++;
  23.       }
  24.       if (item == 'A')
  25.       {
  26.         counterA++;
  27.       }
  28.     }
  29.  
  30.     while (counterT >= 2 && counterA > 0)
  31.     {
  32.       counterAdvertisments++;
  33.       counterA--;
  34.       counterT = counterT - 2;
  35.     }
  36.  
  37.     Console.WriteLine(counterAdvertisments);
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement