Algorithm
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.
Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.
![](https://espresso.codeforces.com/9f468c8e2a165d702e0b35955910a2e841e399d6.png)
The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
ABABBBACFEYUKOTT
4
AAA
1
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
vector<int> arr;
int res = 0;
string s;
cin >> s;
arr.push_back(-1);
for(int i = 0, len = s.length(); i < len; i++)
if(s[i] == 'A' || s[i] == 'E' ||
s[i] == 'U' || s[i] == 'I' ||
s[i] == 'O' || s[i] == 'Y')
arr.push_back(i);
arr.push_back(s.length());
for(int i = 0, len = arr.size() - 1; i < len; i++)
res = max(res, arr[i+1] - arr[i]);
if(arr.size() == 2) {
cout << s.length() + 1 << endl;
else
if(!res)
cout << 1 << endl;
else
cout << res << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
Demonstration
Codeforces Solution-Grasshopper And the String-Solution in C, C++, Java, Python