</pre><pre name="code" class="cpp">#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1000010];
int main()
{
int T;scanf("%d",&T);
for(int t=1;t<=T;t++)
{
scanf("%s",s);
int pre=0,mark=0,ans=0,pos=0;
for(;s[pos]!='\0'&&s[pos]=='f';pos++) pre++;
if(s[pos]=='\0') {printf("Case #%d: %d\n",t,(pre+1)>>1);continue;}
for(int i=++pos;ans!=-1;i++)
{
if(s[i]=='f') mark++;
else if(s[i]=='\0')
{
if(pre+mark>=2)
ans++;
else
ans=-1;
break;
}
else if(s[i]=='c')
{
if(mark<2)
ans=-1;
else
{
ans++;
mark=0;
}
}
}
printf("Case #%d: %d\n",t,ans);
}
}
08-24
08-24