Fang Fang---hud5455(字符串处理)
2015-09-20 10:58
260 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5455
就是求字符串中含有几个f[i], 输出最小的;
例如fff应该是2,有f[0]和f[1]组成的;
ffcffc也是2是有个cff组成的,因为字符串是一个环;
就是求字符串中含有几个f[i], 输出最小的;
例如fff应该是2,有f[0]和f[1]组成的;
ffcffc也是2是有个cff组成的,因为字符串是一个环;
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define N 1010000 char s ; int main() { int T, t=1, cnt, len, flag, ans; scanf("%d", &T); while(T--) { scanf("%s", s); len = strlen(s); cnt=flag=ans=0; for(int i=0; i<len; i++) { if(s[i]!='c'&&s[i]!='f')///出现其他字符; { flag = 1; break; } if(s[i] == 'f')///以便判断是否全是f; cnt++; if(s[i] == 'c') { if(i<=len-3&&s[i+1]=='f'&&s[i+2]=='f') ans++; else if(i==len-2&&s[i+1]=='f'&&s[0]=='f') ans++; else if(i==len-1&&s[0]=='f'&&s[1]=='f') ans++; else { flag=1; break; } } } if(cnt==len) { printf("Case #%d: %d\n", t++, (len+1)/2); } else if(flag==1) { printf("Case #%d: -1\n", t++); } else printf("Case #%d: %d\n", t++, ans); } return 0; }
相关文章推荐
- poj 3259-- Wormholes(SPFA)
- 天声人語 20150920
- JavaScript多级菜单含有源码效果图示例
- 三种常见的图像处理双三次插值算法
- poj 3259-- Wormholes(SPFA)
- C++动态分配内存(new)和撤销内存(delete)
- 一步一步实现500px引导动画
- poj2540Hotter Colder【半平面交求线性规划面积】
- 盘点iOS9最受期待的10大新功能
- UC/OS II 消息邮箱
- HDU 5464:Clarke and problem
- BestCoder Round #56 1002 hdu 5464 (背包问题)
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme
- HDU 5464:Clarke and problem
- debug调试
- Android0918<二十二>(自定义View的属性,下载显示球)
- @property
- 为什么数组开大了codeblock就无法工作了?
- python之if和while控制流
- 什么能带来智能家居智能化酒店?