Sample Input
7
gggaaaooo
aaoogggoa
googgaaao
agogaooag
goooggaaa
gogogoaaa
gaogaogao
Sample Output
3
3
2
1
3
2
1


#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define ZERO(X) memset((X),0,sizeof(X))

using namespace std;

#define quickio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
/*      debug("Precalc: %.3f\n", (double)(clock()) / CLOCKS_PER_SEC);
clock_t z = clock();
solve();
//debug("Test: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
*/
using namespace std;
int main()
{
quickio;
int T;
int ans;
int a,g,o;
cin>>T;
while(T--)
{
string st,s1;
cin>>st;
ans=a=g=o=0;
if(st.find("aaa",0)!=-1)
{
st.erase(st.find("aaa",0),3);
ans++;
}
else if(st.find("ggg",0)!=-1)
{
st.erase(st.find("ggg",0),3);
ans++;
}
else if(st.find("ooo",0)!=-1)
{
st.erase(st.find("ooo",0),3);
ans++;
}
else
{
s1=st;
rep(i,0,2)
{
s1.erase(s1.find("a",0),1);
}
if(s1.find("ggg",0)!=-1)
{
s1.erase(s1.find("ggg",0),3);
a++;
}
else if(s1.find("ooo",0)!=-1)
{
s1.erase(s1.find("ooo",0),3);
a++;
}
s1=st;
rep(i,0,2)
{
s1.erase(s1.find("g",0),1);
}
if(s1.find("aaa",0)!=-1)
{
s1.erase(s1.find("aaa",0),3);
g++;
}
else if(s1.find("ooo",0)!=-1)
{
s1.erase(s1.find("ooo",0),3);
g++;
}
s1=st;
rep(i,0,2)
{
s1.erase(s1.find("o",0),1);
}
if(s1.find("ggg",0)!=-1)
{
s1.erase(s1.find("ggg",0),3);
o++;
}
else if(s1.find("aaa",0)!=-1)
{
s1.erase(s1.find("aaa",0),3);
o++;
}
}
if(ans==1)
{
if(st.find("aaa",0)!=-1||st.find("ggg",0)!=-1||st.find("ooo",0)!=-1)
ans++;
}
else
ans=max(a,max(g,o));
ans++;
cout<<ans<<endl;
}

return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120