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 > 2Write 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.
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 F to split S according to aforementioned rules. Repetitive strings should be counted repeatedly.
Sample Input8ffcfffcffcffcffcfffcffcffcffcfffffcffcfffcffcfffcffffcfffffcffcffc Sample OutputCase #1: 3Case #2: 2Case #3: 2Case #4: -1Case #5: 2Case #6: 4Case #7: 1Case #8: -1HintShift the string in the first test case, we will get the string "cffffcfffcff"and it can be split into "cffff", "cfff" and "cff".
**************************************************
题意:f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2,给你一个字符串,问你最少有多少个f里面的东西组成
分析:把前两个直接拼接到最后,然后扫C的位置,看后面是否跟着两个f,注意可能含有其他字母,可能全是f
AC代码:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 using namespace std;10 #define N 101000011 #define INF 0x3f3f3f3f12 13 char s[N];14 15 int main()16 {17 int k=1,T,i;18 19 scanf("%d",&T);20 21 while(T--)22 {23 scanf("%s", s);24 25 int f=0,ans=0;26 int len=strlen(s);27 28 s[len]=s[0];///ffcffc结果是329 s[len+1]=s[1];30 31 for(i=0; i