传送门

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

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(简单字符串)的更多相关文章

  1. HDU 5907 Find Q dp

    Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...

  2. HDU 5907 Find Q (水题)

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

  3. hdu 5059 简单字符串处理

    http://acm.hdu.edu.cn/showproblem.php?pid=5059 确定输入的数是否在(a,b)内 简单字符串处理 #include <cstdio> #incl ...

  4. CF 208A Dubstep(简单字符串处理)

    题目链接: 传送门 Dubstep Time Limit: 1000MS     Memory Limit: 32768 KB Description Vasya works as a DJ in t ...

  5. 第一部分之简单字符串SDS(第二章)

    一,什么是SDS? 1.引出SDSC字符串:c语言中,用空字符结尾的字符数组表示字符串简单动态字符串(SDS):Redis中,用SDS来表示字符串.在Redis中,包含字符串值的键值对在底层都是由SD ...

  6. C 封装一个通用链表 和 一个简单字符串开发库

    引言 这里需要分享的是一个 简单字符串库和 链表的基库,代码也许用到特定技巧.有时候回想一下, 如果我读书的时候有人告诉我这些关于C开发的积淀, 那么会走的多直啊.刚参加工作的时候做桌面开发, 服务是 ...

  7. 1442: Neo 的简单字符串(字符串)

    1442: Neo 的简单字符串 时间限制: 10 Sec 内存限制: 128 MB 提交: 9 解决: 3 统计 题目描述 Neo 给你一系列字符串,请你输出字符串中的不同单词个数以及总单词个数. ...

  8. 【50.26%】【hdu 5907】Find Q

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) 问题描述 Byteasar迷恋上了 ...

  9. HDU 4500 小Q系列故事——屌丝的逆袭(简单题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4500 AC代码: #include<math.h> #include<stdio.h> ...

随机推荐

  1. lecture13-BP算法的讨论和置信网

    这是HInton课程第13课,这一课有两篇论文可以作为课外读物<Connectionist learning of belief networks>和<The wake-sleep ...

  2. 从零开始打造个人专属命令行工具集——yargs完全指南

    前言 使用命令行程序对程序员来说很常见,就算是前端工程师或者开发gui的,也需要使用命令行来编译程序或者打包程序 熟练使用命令行工具能极大的提高开发效率,linux自带的命令行工具都非常的有用,但是这 ...

  3. 【分布式协调器】Paxos的工程实现-cocklebur选举

    其实整个项目中一个最主要的看点就是选举算法,而这部分也是逻辑最复杂最难理解的部分.不同的实现在不同的场景下的策略也不尽相同,而且场景非常之多.接下来我们一起来看一下Cocklebur的实现思路. 一个 ...

  4. java并发:线程池、饱和策略、定制、扩展

    一.序言 当我们需要使用线程的时候,我们可以新建一个线程,然后显式调用线程的start()方法,这样实现起来非常简便,但在某些场景下存在缺陷:如果需要同时执行多个任务(即并发的线程数量很多),频繁地创 ...

  5. 匈牙利算法(codevs2776)

    type node=^link; link=record des:longint; next:node; end; var n,m,i,t,num:longint; p:node; nd:..] of ...

  6. C#实现每隔一段时间执行代码(多线程)

    总结以下三种方法,实现c#每隔一段时间执行代码: 方法一:调用线程执行方法,在方法中实现死循环,每个循环Sleep设定时间: 方法二:使用System.Timers.Timer类: 方法三:使用Sys ...

  7. ContentProvider备份短信,以xml文件存储

    因为短信的内容已经通过ContentProvider暴露出来,所以我们可以直接用内容解析者获取短信内容. 想要获取短信内容,你需要知道的一些东西: 1.Uri uri = Uri.parse(&quo ...

  8. windows注册表学习笔记

    注册表,想起来了就学学,方便操作.无需把它当成重要学问,今日就学一波,作为了解. 一.注册表清理脚本 主要是删除临时文件,旧文件.并不能够删除无效的键 @echo off del/f/s/q %sys ...

  9. Adobe Flash builder 4.6破解教程(以win764bit为例)

    首先安装软件至默认路径: C:\Program Files(X86)\Adobe下 然后: 1.C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6 ...

  10. make the innerText in the html element can not be selected

    approach style="-moz-user-select:none;" onselectstart="javascript:return false;" ...