传送门

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. Ubuntu环境下安装TinyOS系统

    1.输入下面命令会弹出source list窗口   1 sudo gedit /etc.apt/sources.list 在尾部添加以下地址:   1 2 deb http://tinyos.sta ...

  2. SQLServer(MSSQL)、MySQL、SQLite、Access相互迁移转换工具 DB2DB v1.3

    最近公司有一个项目,需要把原来的系统从 MSSQL 升迁到阿里云RDS(MySQL)上面.为便于测试,所以需要把原来系统的所有数据表以及测试数据转换到 MySQL 上面.在百度上找了很多方法,有通过微 ...

  3. 【语言基础】c++ 备忘录

    1. C++ 整数类型范围 可以参照头文件limits.h定义的宏 #define INT_MAX       2147483647(32bit, 最大10位十进制) #define UINT_MAX ...

  4. .Net 异步方法加上“timeout”

    在本羊读大学的时候,Thread让本羊云里雾里,代码写的痛不欲生,真的是让本羊脑袋里很多“线”缠绕在一起. 之后,Task让本羊代码写的飞起,甚至有时候根本不需要Task的时候还是要写上,那样显得档次 ...

  5. WPF 小技巧

    在使用mvvm模式开发时,对于Command的绑定是一件很伤脑筋的事情,尽管有强大的Blend类库支持: xmlns:Custom="http://www.galasoft.ch/mvvml ...

  6. 项目分享二:APP 小红点中数字的处理

    小红点,是 APP 中最常见的一个功能,我们先来看一下面的案例,下图中,待评价的商品有 2 个,点击“评价晒单”按钮进行评价后,那么待评价数量应该变成 1,那么这个功能是如何去实现的呢? 一般来说,实 ...

  7. 网络功能虚拟化(NFV)

    你造什么是网络功能虚拟化(NFV)吗? NFV将网络功能整合到行业标准的服务器.交换机和存储硬件上,提供了优化的虚拟化数据平面,NFV通过服务器上运行的软件让管理员取代传统物理网络设备,并降低成本.能 ...

  8. JavaScript学习笔记-简单的计时钟表

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  9. java用字符写字符

    import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.GraphicsEnvir ...

  10. 关于最近折腾的ubuntu12.10

    win7旗舰正版up1 UltraISO + ubuntu-12.10-desktop-i386.iso + 4GKingston = 启动U盘 USB HDD 启动 进入ubuntu桌面,安装,磁盘 ...