Advertisement
stanevplamen

03.02.08.Wizard

Jul 26th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. using System;
  2.  
  3. class Wizard
  4. {
  5.     static void Main()
  6.     {
  7.         string inputNumbs = Console.ReadLine(); //"4 4";
  8.         string inputLine = Console.ReadLine(); //"GGGGBBBBBGG";
  9.  
  10.         string[] splitedInput = inputNumbs.Split();
  11.  
  12.         int maxRights = int.Parse(splitedInput[0]);
  13.         int maxWrongs = int.Parse(splitedInput[1]);
  14.  
  15.         int[] arrayOfSum = new int[inputLine.Length + 1];
  16.         int counter = 0;
  17.         arrayOfSum[0] = 0;
  18.         bool gCycle = false;
  19.         bool bCycle = false;
  20.  
  21.         for (int i = 0; i < inputLine.Length ; i++)
  22.         {
  23.             counter++;
  24.             if (inputLine[i] == 'G')
  25.             {
  26.                 if (bCycle == true)
  27.                 {
  28.                     counter = 1;
  29.                 }
  30.                 gCycle = true;
  31.                 bCycle = false;
  32.                 if (counter <= maxRights)
  33.                 {
  34.                     arrayOfSum[i + 1] = arrayOfSum[i] + 1;
  35.                 }
  36.                 else
  37.                 {
  38.                     arrayOfSum[i + 1] = arrayOfSum[i];
  39.                     counter = 0;
  40.                 }
  41.             }
  42.             else // (inputLine[i] == 'B')
  43.             {
  44.                 if (gCycle == true)
  45.                 {
  46.                     counter = 1;
  47.                 }
  48.                 bCycle = true;
  49.                 gCycle = false;
  50.                 if (counter <= maxWrongs)
  51.                 {
  52.                     arrayOfSum[i + 1] = arrayOfSum[i] + 1;
  53.                 }
  54.                 else
  55.                 {
  56.                     arrayOfSum[i + 1] = arrayOfSum[i];
  57.                     counter = 0;
  58.                 }
  59.             }
  60.         }
  61.         Console.WriteLine(arrayOfSum[arrayOfSum.Length - 1]);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement