标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char s[100006]; 6 int main() 7 { 8 int t,i,ans,j,flag,k=1,a; 9 scanf("%d",&t); 10 getchar(); 11 while (t--) 12 { 13 flag=0; 14 gets(s); 15 if (s[0]==‘ ‘) 16 { 17 printf("Case #%d: ",k); 18 k++; 19 printf("0\n"); 20 continue; 21 } 22 for (i=0;s[i];i++){ 23 if (s[i]!=‘c‘&&s[i]!=‘f‘) {flag=1;break;} 24 if (s[i]==‘c‘) break; 25 } 26 if (s[i]==‘\0‘) 27 { 28 printf("Case #%d: ",k); 29 k++; 30 printf("%d\n",i/2+i%2); 31 continue; 32 } 33 a=i; 34 ans=1; 35 j=0; 36 for (i=i+1;s[i];i++) 37 { 38 if (s[i]!=‘c‘&&s[i]!=‘f‘) {flag=1;break;} 39 if (s[i]!=‘c‘) j++; 40 else 41 { 42 if (j>=2) 43 { 44 j=0; 45 ans++; 46 } 47 else 48 { 49 flag=1; 50 break; 51 } 52 } 53 } 54 if (j+a<2) flag=1; 55 printf("Case #%d: ",k); 56 if (flag) printf("-1\n"); 57 else printf("%d\n",ans); 58 k++; 59 } 60 }
标签:
原文地址:http://www.cnblogs.com/pblr/p/4822000.html