# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
851456 | omarkhaled | Laugh Analysis (IOI16_laugh) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define oo 1e9
void fast()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int longest_laugh(string s)
{
int cnt = 0;
for (int i = 0; i < sz(s); i++)
{
if (s[i] == 'a' || s[i] == 'h')
{
int j = i;
bool ha;
if (s[i] == 'h')
ha = 0;
else
ha = 1;
i++;
while (i < sz(s))
{
if (s[i] == 'h' && ha)
{
i++;
ha = 0;
}
else if (s[i] == 'a' && !ha)
{
i++;
ha = 1;
}
else
break;
}
cnt = max(cnt, i - j);
}
}
return cnt;
}
void solve()
{
string s;
cin >> s;
cout << longest_laugh(s);
}
int main()
{
fast();
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}