# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
851456 | omarkhaled | Laugh Analysis (IOI16_laugh) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}