Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- int main()
- {
- std::string str;
- std::cout << "Enter your text: " << std::endl;
- std::getline(std::cin, str);
- int number_of_a(0);
- int best(0);
- bool was_any_a = false;
- for (int i = 1; i < str.length(); i++)
- {
- if (str.at(i) == 'a')
- {
- was_any_a = true;
- if (str.at(i-1) == 'a')
- {
- number_of_a++;
- best = (best <= number_of_a) ? number_of_a : best;
- } else if (i<(str.length()-1))
- {
- if (str.at(i+1) == 'a')
- {
- number_of_a++;
- best = (best <= number_of_a) ? number_of_a : best;
- }
- };
- } else number_of_a = 0;
- }
- best = ((best == 0) && (was_any_a)) ? 1 : best;
- std::cout << "There are " << best << " of MAX Sequence of A" << std::endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement