Suppose we have a string S with n characters. S is a single-space separated words, consisting of small and capital English letters. Volume of the word is number of capital letters in the given word. And volume of the text is maximum volume of all words in the text. We have to find the volume of the given text.
Steps
To solve this, we will follow these steps −
ans := 0 a := 0 n := size of S for initialize i := 0, when i <= n, update (increase i by 1), do: s := S[i] if s >= 'A' and s <= 'Z', then: (increase a by 1) if s is same as blank space, then: ans := maximum of ans and a a := 0 ans := maximum of ans and a return ans
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h>
using namespace std;
int solve(string S){
int ans = 0, a = 0;
int n = S.size();
for (int i = 0; i <= n; i++){
char s = S[i];
if ((s >= 'A') && (s <= 'Z'))
a++;
if (s == ' '){
ans = max(ans, a);
a = 0;
}
}
ans = max(ans, a);
return ans;
}
int main(){
string S = "Paper MILL";
cout << solve(S) << endl;
}Input
"Paper MILL"
Output
4