Fang Fang hdu 5455

http://acm.hdu.edu.cn/showproblem.php?pid=5455

题意:判断字符串最少符合题意的个数,它是一个环。若c前面有f,则把f的个数都加到后面去。还有一个坑点是,会有其他字母,不止有c,f。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define INF 0x3f3f3f3f
const int maxn = 110000;
char str[maxn];
typedef long long LL;

int main()
{
   int T, cnt=1;

   scanf("%d", &T);

   while(T --)
   {
       scanf("%s", str);

       int flag = 0;
       ///判断有没有其他字母
       for(int i=0; str[i]; i++)
      if(str[i]!=‘c‘ && str[i]!=‘f‘)
       {
           flag = 1;
           break;
       }

       if(flag)
       {
          printf("Case #%d: -1\n", cnt++);
           continue;
       }

       int k=0;

       ///判断是否全部为f
       while(str[k]==‘f‘) k++;
       int len = strlen(str);
       ///若全部为f则输出(k+1)/2,因为要求最少的个数,所以两个f在一块才会最少,一个f也符合情况
        if(k==len&&str[k]!=‘c‘)
        {
            printf("Case #%d: %d\n", cnt++, (k+1)/2);
            continue;
        }

       int ans = 0;
       int f = 0;

       ///已经判断过是否只有c和f了,所以k+1一定为f
       for(int i=k+1; str[i]; i++)
       {
           if(str[i]==‘c‘)
           {
              if(f>1) ans ++;///若符合题意,则ans+1:
              else///若不符合题意,则直接跳出循环,输出“-1”
              {
                  flag =1;
                  break;
              }
               f = 0;
           }
           else if(str[i]==‘f‘)
            f ++;
       }

       if(f+k>1) ans++;///判断最后一个c后面的f的个数是否符合题意
       else flag = 1;

       if(flag) printf("Case #%d: -1\n", cnt++);
       else printf("Case #%d: %d\n",cnt++, ans);
   }
    return 0;
}
/*
99
fffff
fff
ccff
fds
cfcf
fffcffcf
*/

时间: 2024-10-01 02:41:32

Fang Fang hdu 5455的相关文章

hdu 5455 Fang Fang 坑题

Fang Fang Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5455 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",F

(字符串处理)Fang Fang -- hdu -- 5455 (2015 ACM/ICPC Asia Regional Shenyang Online)

链接: http://acm.hdu.edu.cn/showproblem.php?pid=5455 Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 233    Accepted Submission(s): 110 Problem Description Fang Fang says she wants to be

HDU - 5455 Fang Fang

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,

Fang Fang HDU - 5455 (思维题)

Fang Fang says she wants to be remembered. I promise her. We define the sequence FF of strings. F0 = ''f",F0 = ''f", F1 = ''ff",F1 = ''ff", F2 = ''cff",F2 = ''cff", Fn = Fn?1 + ''f", for n > 2Fn = Fn?1 + ''f", fo

HDU5455 沈阳网络赛 Fang Fang

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意是 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 a

hdu 5455(字符串处理)

Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1317    Accepted Submission(s): 548 Problem Description Fang Fang says she wants to be remembered.I promise her. We define the sequence

Fang Fang

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,

hdu 5455 (2015沈阳网赛 简单题) Fang Fang

题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不满足条件的,还有我被坑了的地方就是当输入很多f的时候,我尽然脑抽的 认为这是不满足条件的,注意这两点就行了,直接暴力 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int

HDU 5455 Fang Fang 水题,但题意描述有问题

题目大意:f[1]=f,f[2]=ff,f[3]=ffc,以后f[n]每增加1,字符串增加一个c.给出一个字符串,求最少有多少个f[]组成.(字符串首尾相连,比如:ffcf可看做cfff) 题目思路:判断多少个c,但是每个c之间必须有两个f,首尾的c也应判断首尾相连后两者之间的距离.坑点在与 1.给出的字符串中可能包含其它字符 2.严格按照gets()读入 3.若不含c,求有多少个f[2],若有多余补上一个f[1] 3.1.出题人神经病 #include<cstdio> #include<