Problem Description
Fang Fang says she wants to be remembered.
I promise her. We define the sequence F of strings.
F0 = ‘‘f",
F1 = ‘‘ff",
F2 = ‘‘cff",
Fn = Fn−1 + ‘‘f", for n > 2
Write down a serenade as a lowercase string S in a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in F, or nothing could be done but put her away in cold wilderness.
I promise her. We define the sequence F of strings.
F0 = ‘‘f",
F1 = ‘‘ff",
F2 = ‘‘cff",
Fn = Fn−1 + ‘‘f", for n > 2
Write down a serenade as a lowercase string S in a circle, in a loop that never ends.
Spell the serenade using the minimum number of strings in F, or nothing could be done but put her away in cold wilderness.
Input
An positive integer T, indicating there are T test cases.
Following are T lines, each line contains an string S as introduced above.
The total length of strings for all test cases would not be larger than 106.
Following are T lines, each line contains an string S as introduced above.
The total length of strings for all test cases would not be larger than 106.
Output
The output contains exactly T lines.
For each test case, if one can not spell the serenade by using the strings in F, output −1. Otherwise, output the minimum number of strings in Fto split S according to aforementioned rules. Repetitive strings should be counted repeatedly.
For each test case, if one can not spell the serenade by using the strings in F, output −1. Otherwise, output the minimum number of strings in Fto split S according to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input
8
ffcfffcffcff
cffcfff
cffcff
cffcf
ffffcffcfff
cffcfffcffffcfffff
cff
cffc
Sample Output
Case #1:3
Case #2: 2
Case #3: 2
Case #4: -1
Case #5: 2
Case #6: 4
Case #7: 1
Case #8: -1
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 "); 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]=='