水题-find q
来源:互联网 发布:儿童电脑画图软件 编辑:程序博客网 时间:2024/05/17 22:30
Byteasar is addicted to the English letter 'q'. Now he comes across a string S Sconsisting of lowercase English letters.
He wants to find all the continous substrings ofS S, which only contain the letter 'q'. But this string is really really long, so could you please write a program to help him?
He wants to find all the continous substrings of
In each test case, there is a string
2qoderquailtyqqq
17
这道题其实不难,但是本人是个菜鸟,超时了好几次。先解释一下题意,在已知的字符串中寻找只含有q的
子字符串,这个规律其实很好找,找到规律后就很简单了,为了不超时,可以用数组打一个简单的表,直
接提取就好了,这个和那个汉罗塔的变式很相似,废话不多说,下面上代码。
#include<cstdio> #include<cstring> #include<iostream> #define N 100005 using namespace std; int main() { int i,t; long long sum[N]; char s[N]; sum[1]=1; for(i=2;i<=N;i++) sum[i]=sum[i-1]+i; scanf("%d",&t); while(t--) { int cnt=0,len; long long ass=0; scanf("%s",s+1); len=strlen(s+1); for(i=1;i<=len+1;i++) { if(s[i]=='q') cnt++; else { ass=ass+sum[cnt]; cnt=0; } } printf("%lld\n",ass); } return 0; }
0 0
- 水题-find q
- Find Q
- Find Q
- Find Q
- HDU:5907 Find Q(水题)
- BestCoder Round#88 1001 Find Q 水题
- 【5907Find Q】
- HDU5907-Find Q
- hdu5907 Find Q (统计)
- hdu 5907 Find Q
- HDU 5907 Find Q
- hdoj-【5907 Find Q】
- HDU 5907 Find Q
- 【HDOJ】5907 Find Q
- HDU:5907 Find Q
- hdu 5907 Find Q
- HDU 5907 Find Q
- find q hdu
- Java动态代理机制详解(JDK 和CGLIB,Javassist,ASM)
- JavaScript语言特性
- Dragon of Loowater UVA
- URL模拟登陆出现的小问题(新手)
- 关于Online Judge题目tick and tick的数学公式推导
- 水题-find q
- python模块win32com下载
- TabLayout和Viewpage连用
- 天梯赛练习——到底有多二
- 因为这游戏一旦开始 从未有谁能够把它停下
- iOS开发:UIButton的两个小坑
- 图形学基础(3)——模型变换动画
- 98:Maximal Rectangle
- POJ 3187 Backward Digit Sums