Find Q

题目连接:

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

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

For each test case, print a line with an integer, denoting the number of continous substrings of S, which only contain the letter 'q'.

Sample Input

2

qoder

quailtyqqq

Sample Output

1

7

Hint

题意

问你有多少个子串,全部只含有q这个字母。

题解:

直接dp就好了,dp[i]表示以i结尾的方案数。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 100007;
long long dp[maxn];
void solve()
{
string s;
cin>>s;
memset(dp,0,sizeof(dp));
for(int i=0;i<s.size();i++)
if(s[i]=='q')dp[i]=dp[i-1]+1;
long long ans = 0;
for(int i=0;i<s.size();i++)
ans+=dp[i];
cout<<ans<<endl;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve(); }

HDU 5907 Find Q dp的更多相关文章

  1. HDU 5907 Find Q(简单字符串)

    传送门 Description Byteasar is addicted to the English letter 'q'. Now he comes across a string S consi ...

  2. HDU 5907 Find Q (水题)

    题意:在他眼前有一个小写字母组成的字符串SSS,他想找出SSS的所有仅包含字母'q'的连续子串. 析:这个题,很容易发现,有 n 个连续个q,就是前 n 项和.注意不要超 int. 代码如下: #pr ...

  3. hdu 2296 aC自动机+dp(得到价值最大的字符串)

    Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  5. 2014多校第一场J题 || HDU 4870 Rating(DP || 高斯消元)

    题目链接 题意 :小女孩注册了两个比赛的帐号,初始分值都为0,每做一次比赛如果排名在前两百名,rating涨50,否则降100,告诉你她每次比赛在前两百名的概率p,如果她每次做题都用两个账号中分数低的 ...

  6. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  7. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  8. HDOJ(HDU).2546 饭卡(DP 01背包)

    HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为 ...

  9. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

随机推荐

  1. mysql 创建用户自定义函数

    为了防止分号产生的中途输出,自己定义一个 分隔符,这里仿照mysql官方的例子:使用两个美元符号 $$ 作为分割符号,下面这段代码就是创建一个自定义mysql函数的原型了,可以在这个基础上修改,这样, ...

  2. CSS-3 新弹性盒模型属性

    flex 语法:flex:none | [ flex-grow ] || [ flex-shrink ] || [ flex-basis ] 取值: none:none关键字的计算值为: 0 0 au ...

  3. 蓝桥杯 问题 1110: 2^k进制数 (排列组合+高精度巧妙处理)

    题目链接 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2 ...

  4. [HAOI2008]移动玩具(状压&带权二分图)

    题目描述 • 一个 4 × 4 的 0/1 矩阵 • 每次可以交换相邻两个元素 • 求从初始状态到目标状态的最小交换次数 输入格式 前四行,每行一个长为 4 的 0/1 字符串,描述初始状态. 后四行 ...

  5. Oracle Logminer 分析重做日志RedoLog和归档日志ArchiveLog

    在实际开发过程中,有时我们很有可能需要某个表的操作痕迹,或通过记录的SQL语句进行有目的性的数据恢复(此时POINT-IN-TIME恢复已经满足不了更细的粒度).或仅仅是查看: 据说Oracle8i之 ...

  6. JS异常简单处理

    有时候JS某一处报错会导致整个页面JS的运行出问题,于是想的简单研究一下JS的错误处理机制.更详细的可以自己参考网站研究:   https://developer.mozilla.org/zh-CN/ ...

  7. mybatis延迟加载——(十二)

    1.     什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能 ...

  8. JDK1.8源码hashMap

    一.概念 允许key为null,value为null:线程不安全:不保证映射的顺序:迭代 collection 视图所需的时间与 HashMap 实例的“容量”(桶的数量)及其大小(键-值映射关系数) ...

  9. os_mudule_docs

    pydoc os Help on module os: NAME os - OS routines for Mac, NT, or Posix depending on what system we' ...

  10. 八、mini2440裸机程序之UART(1)简单介绍【转】

    转自:http://blog.csdn.net/shengnan_wu/article/details/8298869 一.概述          S3C2440通用异步接收和发送(UART)提供了三 ...