您的位置:首页 > 其它

whust #0.1 I - Laughing Out Loud

2015-08-09 16:13 246 查看
I - Laughing Out Loud
Time Limit:1000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice Gym 100589I

Description

standard input/output

Little Toojee was a happy go lucky boy. He seemed to find most, if not all, things funny. One day he read a word and started laughing a lot. Turns out that the word consisted only of the letters L and O. Whenever he saw the subsequence ‘LOL’ in the word, he laughed for 1 second. Given t strings, find out for how long Toojee laughed on seeing each string.

Input

The first line contains t queries. This is followed by t lines each containing one string S. String S consists only of capital alphabets.

Output

Output for each string on a new line.

Constraints

1  ≤ t ≤ 10

1  ≤ |S| ≤ 105

Sample Input

Input
2
LOL
LOLOL


Output
1
4


Hint

Test1: On observation, we can tell that there is only 1 occurrence of LOL.

Test2: Let the string be 0-indexed and let V = {a, b, c} denote the indices that make up the string “LOL”, where a is index of the 1st ‘L’, b is index of the ‘O’ and c is the index of the 2nd ‘L’. So, V can be {0, 1, 2}, {2, 3, 4}, {0, 1, 4} and {0, 3, 4}. We see that there are 4 occurrences of the string “LOL”.

又是求有多少种组合的题.

和上次cf那道求等比数列的非常像.

/*************************************************************************
> File Name: code/whust/#0.1/II.cpp
> Author: 111qqz
> Email: rkz2013@126.com
> Created Time: 2015年08月09日 星期日 16时00分44秒
************************************************************************/

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<stack>
#define y0 abc111qqz
#define y1 hust111qqz
#define yn hez111qqz
#define j1 cute111qqz
#define tm crazy111qqz
#define lr dying111qqz
using namespace std;
#define REP(i, n) for (int i=0;i<int(n);++i)
typedef long long LL;
typedef unsigned long long ULL;
const int inf = 0x7fffffff;
int main()
{
int T;
cin>>T;
string st;
while (T--)
{
cin>>st;
int len = st.length();
LL p=0,q=0;
LL ans = 0 ;
for ( int i = 0 ; i < len ; i ++)
{
if (st[i]=='L')
{
p++;
ans = ans + q;
}
else
{
q = q+ p; //p为L的个数,q表示前面有"LO"组合的个数
}
}
cout<<ans<<endl;
}

return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: