Problem Description
Fang Fang says she wants to be remembered.
I promise her. We define the sequence F, or nothing could be done but put her away in cold wilderness.
 
Input
An positive integer 6.
 
Output
The output contains exactly 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
Hint

Shift the string in the first test case, we will get the string "cffffcfffcff"
and it can be split into "cffff", "cfff" and "cff".

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5455

**************************************************

题意:f1 = f,f2 = ff, f3 = cff ,fn = fn-1+fn-2,给你一个字符串,问你最少有多少个f里面的东西组成

分析:把前两个直接拼接到最后,然后扫C的位置,看后面是否跟着两个f,注意可能含有其他字母,可能全是f

AC代码:

 

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<queue>
 7 #include<stdlib.h>
 8 
 9 using namespace std;
10 #define N  1010000
11 #define INF 0x3f3f3f3f
12 
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结果是3
29         s[len+1]=s[1];
30 
31         for(i=0; i<len; i++)///输入有可能存在其他的字符
32         {
33             if(s[i]=='c'||s[i]=='f')
34                 continue ;
35             else
36             {
37                 f=1;
38                 break;
39             }
40         }
41 
42         for(i=0;i<len;i++)
43         {
44             if(f==0)
45             {
46                 if(s[i]=='c')
47                 {
48                     if(s[i+1]=='f'&&s[i+2]=='f')
49                     {
50                         i++;
51                         while(i<len&&s[i]=='f')///遇见c跳出
52                             i++;
53                         ans++;///个数加一
54                         i--;
55                     }
56                     else
57                         f=1;
58                 }
59             }
60         }
61 
62         printf("Case #%d: ",k++);
63         if(f==1)
64             printf("-1\n");
65         else if(ans==0)///全是f
66             printf("%d\n", len/2+len%2);
67         else
68             printf("%d\n", ans);
69     }
70     return 0;
71 }

 

 

 

相关文章:

  • 2021-12-03
  • 2021-09-08
  • 2021-12-20
  • 2022-01-01
  • 2021-06-14
  • 2021-11-19
  • 2022-01-04
  • 2021-11-06
猜你喜欢
  • 2021-12-30
  • 2021-09-10
  • 2021-09-08
  • 2022-01-18
  • 2021-12-11
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案