zoukankan      html  css  js  c++  java
  • HDU 5907 Find Q dp

    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();
    
    }
  • 相关阅读:
    Linux系统常见的压缩与打包
    java 语言规范 java language specifications
    java 枚举
    github邮箱验证技巧
    关于 python
    博客园 编程基础 精华
    fiddler
    一个牛人写的博客
    使用xmarks同步 chrome ie firefox safari书签
    linux 中的 tar 解压
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5927564.html
Copyright © 2011-2022 走看看