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. ngx_lua_API 指令详解(六)ngx.thread.spawn、ngx.thread.wait、ngx.thread.kill介绍

    摘要:通过lua-nginx-module中的ngx.thread同时执行多个任务. ngx_lua中访问多个第三方服务 ngx_lua中提供了ngx.socket API,可以方便的访问第三方网络服 ...

  2. javascript 简单工厂模式

    var Bicycle = new Interface("Bicycle",["assemble","wash","ride&qu ...

  3. javascript多种继承方式(函数式,浅复制,深复制,函数绑定和借用)

    函数式继承: var object = function (obj) { if (typeof Object.create !== 'undefined') { return Object.creat ...

  4. iOS代码规范之命名规范

    技术博客http://www.cnblogs.com/ChenYilong/    新浪微博http://weibo.com/luohanchenyilong   命名规范类命名    首字母大写,之 ...

  5. C - 青蛙的约会 POJ - 1061 (扩展欧几里得)

    题目链接:https://cn.vjudge.net/contest/276376#problem/C 题目大意:中文题目. 具体思路:扩展gcd,具体证明过程看图片(就这麽个题我搞了一天,,,). ...

  6. 20165227 2017-2018-2《Java程序设计》课程总结

    20165227 2017-2018-2<Java程序设计>课程总结 每周作业链接汇总 预备作业1 简要内容: 记忆深刻的老师 我期望的师生关系 对于Java学习的看法 预备作业2 简要内 ...

  7. JDK1.8源码Collections

    正文: 一.概述: 此类完全由在 collection 上进行操作或返回 collection 的静态方法组成.它包含在 collection 上操作的多态算法,即“包装器”,包装器返回由指定 col ...

  8. MySql 死锁时的一种解决办法【转】

    转自:http://blog.csdn.net/mchdba/article/details/38313881 之前也遇到一次,今天又遇到了这个问题,所以这次必须解决,网上找到这篇文章帮了大忙,方便以 ...

  9. oracle数据库_实例_用户_表空间之间的关系

    基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的 ...

  10. C#数组 List、Dictionary 、Arrary、ArrayList

    #region Dictionary 泛型集合,动态修改查询.查询和排序 Dictionary<string, string> dic = new Dictionary<string ...