Advertisement
Trapov

Untitled

Mar 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. int main()
  4. {
  5.     std::string str;
  6.     std::cout << "Enter your text: " << std::endl;
  7.     std::getline(std::cin, str);
  8.     int number_of_a(0);
  9.     int best(0);
  10.     bool was_any_a = false;
  11.     for (int i = 1; i < str.length(); i++)
  12.     {
  13.         if (str.at(i) == 'a')
  14.         {
  15.             was_any_a = true;
  16.             if (str.at(i-1) == 'a')
  17.             {
  18.                 number_of_a++;
  19.                 best = (best <= number_of_a) ? number_of_a : best;
  20.             } else if (i<(str.length()-1))
  21.                 {
  22.                     if (str.at(i+1) == 'a')
  23.                     {
  24.                         number_of_a++;
  25.                         best = (best <= number_of_a) ? number_of_a : best;
  26.                     }
  27.                 }; 
  28.         } else number_of_a = 0;
  29.     }
  30.     best = ((best == 0) && (was_any_a)) ? 1 : best;
  31.     std::cout << "There are " << best << " of MAX Sequence of A" << std::endl;
  32.     system("pause");
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement