মান লক্ষ্য করুন একটি n ক্যারেক্টারের স্ট্রিং S। S হলো সিঙ্গল-স্পেস সেপারেটেড শব্দ, ছোট এবং বড় হাতের ইংরেজি অক্ষর থেকে গঠিত। একটি শব্দের ভলিউম হলো সেটিতে বড় হাতের অক্ষরের সংখ্যা। এবং টেক্সটের ভলিউম হলো টেক্সটের সব শব্দের মধ্যে সর্বাধিক ভলিউম। আমাদের দিয়ে गये টেক্সটের ভলিউম বের করতে হবে।
ধাপসমূহ
এটি সমাধান করার জন্য, আমরা এই ধাপগুলো অনুসরণ করব −
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
উদাহরণ
বेहतर বোঝার জন্য ইমপ্লিমেন্টেশন দেখি −
#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;
}
ইনপুট
"Paper MILL"
আউটপুট
4