HDU 5907 Find Q(简单字符串)
Description
Byteasar is addicted to the English letter 'q'. Now he comes across a string S consisting of lowercase English letters.
He wants to find all the continous substrings of S, which only contain the letter 'q'. But this string is really really long, so could you please write a program to help him?
Input
The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.
In each test case, there is a string S, it is guaranteed that S only contains lowercase letters and the length of S is no more than 100000.
Output
Sample Input
2qoder quailtyqqq
Sample Output
17
思路
题意:找出SS的所有仅包含字母'q'的连续子串
只要求出每个位置能往右延伸多长即可。
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 100005;
char a[maxn];
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
__int64 res = 0,cnt = 0;
scanf("%s",a);
int len = strlen(a);
for (int i = 0;i < len;)
{
if (a[i] == 'q')
{
while (a[i] == 'q')
{
i++;
cnt++;
}
res += (1+cnt)*cnt/2;
cnt = 0;
}
else
{
i++;
}
}
printf("%I64d\n",res);
}
return 0;
}
HDU 5907 Find Q(简单字符串)的更多相关文章
- HDU 5907 Find Q dp
Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...
- HDU 5907 Find Q (水题)
题意:在他眼前有一个小写字母组成的字符串SSS,他想找出SSS的所有仅包含字母'q'的连续子串. 析:这个题,很容易发现,有 n 个连续个q,就是前 n 项和.注意不要超 int. 代码如下: #pr ...
- hdu 5059 简单字符串处理
http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...
- CF 208A Dubstep(简单字符串处理)
题目链接: 传送门 Dubstep Time Limit: 1000MS Memory Limit: 32768 KB Description Vasya works as a DJ in t ...
- 第一部分之简单字符串SDS(第二章)
一,什么是SDS? 1.引出SDSC字符串:c语言中,用空字符结尾的字符数组表示字符串简单动态字符串(SDS):Redis中,用SDS来表示字符串.在Redis中,包含字符串值的键值对在底层都是由SD ...
- C 封装一个通用链表 和 一个简单字符串开发库
引言 这里需要分享的是一个 简单字符串库和 链表的基库,代码也许用到特定技巧.有时候回想一下, 如果我读书的时候有人告诉我这些关于C开发的积淀, 那么会走的多直啊.刚参加工作的时候做桌面开发, 服务是 ...
- 1442: Neo 的简单字符串(字符串)
1442: Neo 的简单字符串 时间限制: 10 Sec 内存限制: 128 MB 提交: 9 解决: 3 统计 题目描述 Neo 给你一系列字符串,请你输出字符串中的不同单词个数以及总单词个数. ...
- 【50.26%】【hdu 5907】Find Q
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) 问题描述 Byteasar迷恋上了 ...
- HDU 4500 小Q系列故事——屌丝的逆袭(简单题)
http://acm.hdu.edu.cn/showproblem.php?pid=4500 AC代码: #include<math.h> #include<stdio.h> ...
随机推荐
- 直流调速系统Modelica基本模型
为了便于在OpenModelica进行仿真,形成一个完整的仿真模型,没有使用第三方的库,参照了DrModelica的例程,按照Modelica库的开源模型定义了所用的基本元件模型. 首先给出一些基本类 ...
- 关于printf函数的所思所想
缘起大一下学期,C语言程序设计徐小青老师的随口一提,经娄嘉鹏老师提醒,我觉得应该自己整理清楚这一问题.涉及网上资料将会标明出处. 关于printf函数的所思所想 * printf的定义 printf( ...
- Theano2.1.18-基础知识之theano的扩展
来自:http://deeplearning.net/software/theano/tutorial/extending_theano.html Extending Theano 该教程覆盖了如何使 ...
- 从炉石传说的一个自杀OTK说起
OTK就是one turn kill,不过这次我们要谈的OTK是自杀,对就是自己把自己给OTK了. 其实程序没有任何错误,只是恰巧碰上了这么个死循环. ps:文章最后有代码git地址 发动条件及效果: ...
- SQLite剖析之体系结构
1.通过官方的SQLite架构文档,理清大体的系统层次:Architecture of SQLite 2.阅读SQLite Documentation中Technical/Design Documen ...
- P值与significant(显著性)的理解
P值与significant的理解 来源:广州市统计局 发表日期:2015-01-21 P值可以理解为结论的风险大小,也就是根据数据得出的结果有多大的错误风险,P值越小,结论错误的风险越小 ...
- 用SpringMvc实现Excel导出功能
以前只知道用poi导出Excel,最近用了SpringMvc的Excel导出功能,结合jxl和poi实现,的确比只用Poi好,两种实现方式如下: 一.结合jxl实现: 1.引入jxl的所需jar包: ...
- Spring3+Mybatis3+Mysql+ivy+liquibase
Spring3+Mybatis3+Mysql+ivy+liquibase 集成 近一周时间所学技术:整合Spring+MyBatis+MySql+ivy+liquibase Mybatis:是一个基于 ...
- IOS -- 获取本地图片和网络图片的大小size
// 获取图片的size CGSize size = [UIImage imageNamed:@"regStep2_sex"].size; 获取网络图片的尺寸: // 根据图片ur ...
- springmvc中实现quartz定时任务
1.maven项目添加如下两个jar包,当然也需要相应的spring 的Jar <!-- Spring Quartz定时器 begin --> <dependency> < ...