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. bzoj千题计划194:bzoj2115: [Wc2011] Xor

    http://www.lydsy.com/JudgeOnline/problem.php?id=2115 边和点可以重复经过,那最后的路径一定是从1到n的一条路径加上许多环 dfs出任意一条路径的异或 ...

  2. bzoj千题计划181:bzoj1878: [SDOI2009]HH的项链

    http://www.lydsy.com/JudgeOnline/problem.php?id=1878 之前用莫队做的,现在用树状数组 把每种数的第一个出现位置在树状数组中+1 nxt[i] 记录i ...

  3. Redis五种数据结构(Windows Server)

    1.Redis的五种数据结构 这里推荐大家在命名redis的key的时候最好的加上前缀,并且使用 :来分割前缀 ,这里在使用可视化工具查看的时候就比较好区分,比如我的的前缀是 Demo:test:(一 ...

  4. gcc初步窥探

    由于没有上过Linux编程这门课,所以Linux学得很水啊!!用来用去都是ls -al ; cd .. ;这些渣命令,尤其gcc都不知道什么东西来的,所以先学一下吧. 一.程序的编译过程 对于GUN编 ...

  5. HttpClient与HttpUrlConnection下载速度比较

    Android有两套http的API,刚开始使用网络编程时多少有些迷惑到底用哪个好呢?其实孰优孰劣无需再争论,google已经指出HttpUrlConnection是Android更优的选择,并在SD ...

  6. CF 1131B Draw!

    Draw! Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Descriptio ...

  7. Anaconda+django写出第一个web app(十)

    今天继续学习外键的使用. 当我们有了category.series和很多tutorials时,我们查看某个tutorial,可能需要这样的路径http://127.0.0.1:8000/categor ...

  8. Burp-Suit之Interder

    登陆页面:http://localhost/pentest/brute/login.php 设置代理,使用Burp截断: 发送到Intruder进行爆破,这里我先说明一下Intruder页面 Inte ...

  9. struts与ognl结合【重要】

    -----------------------------ognl表达式------------------------ OGNL:对象视图导航语言.  ${user.addr.name} 这种写法就 ...

  10. 设置linux的console为串口【转】

    转自:http://blog.chinaunix.net/uid-27717694-id-4074219.html 以Grub2为例:1. 修改文件/etc/default/grub   #显示启动菜 ...