BestCoder Roud #88 Find Q

来源:互联网 发布:神枪手交易软件 编辑:程序博客网 时间:2024/05/29 20:00
Problem Description

Byteasar is addicted to the English letter 'q'. Now he comes across a string SSS consisting of lowercase English letters.

He wants to find all the continous substrings of SSS, 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)T(1\leq T\leq10)T(1T10), denoting the number of test cases.

In each test case, there is a string SSS, it is guaranteed that SSS only contains lowercase letters and the length of SSS is no more than 100000100000100000.

Output

For each test case, print a line with an integer, denoting the number of continous substrings ofSSS, which only contain the letter 'q'.

Sample Input
2qoderquailtyqqq
Sample Output
17
#include<iostream>#include <string>using namespace std;int jc( int n ){if( n==0 ) return 0;int sum = 1;for( ; n>=1; n-- ){sum *= n;}return sum;}int main(){string str;cin >> str;int ans = 0;int count = 0;for( int i=0; i<str.size(); i++ ){if( str[i]=='q' )ans++;else{count += jc( ans );ans = 0;}if( i==( str.size()-1) )    count += jc( ans ); }cout << count << endl;return 0;} 


0 0
原创粉丝点击