protagonist

苦逼的单身狗

题目描述

双11又到了,小Z依然只是一只单身狗,对此他是如此的苦恼又无可奈何。
为了在这一天脱单小Z决定向女神表白,但性格腼腆的小Z决定隐晦一点,截取一段包含'L'、'O'、'V'、'E'的英文。(顺序不限)
小Z想起之前小D送给他一本英文书,决定在这里面截取一段话,小Z发现有好多种方案来截取这段话。
你能知道小Z能有多少种方案截取这段话么?
为了简化问题,英文文本讲不会出现空格、换行、标点符号及只有大写的情况。

输入描述:

本题有T组数据。
对于每组数据只有一行文本。
1≤T≤20
1≤文本长度≤100000

输出描述:

输出结果,并换行。
示例1

输入

复制
3
ILOVEACM
LOVELOVE
ALBECVOD

输出

复制
8
15
4

说明

对于第一组数据共有如下8种截取方案
ILOVE
ILOVEA
ILOVEAC
ILOVEACM
LOVE
LOVEA
LOVEAC
LOVEACM
对于第三组数据共有如下4种截取方案
ALBECVO
ALBECVOD
LBECVO
LBECVOD
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+666;
int T,cur,cnt[maxn],ans;
string str,tmp="LOVE";
int main()
{
    cin>>T;
    while(T--){
        cin>>str;
        ans=cur=0;
        memset(cnt,0,sizeof(cnt));
        for(int i=0,r=0;i<str.size();i++){
              while(r<str.size()&&cur<4){
                   for(int j=0;j<4;j++){
                         if(tmp[j]!=str[r])continue;
                         if(!cnt[j])cur++;
                         cnt[j]++;
                   }
                   r++;
              }
              if(cur<4)break;
              ans+=(str.size()-r+1);
              for(int j=0;j<4;j++){
                   if(str[i]==tmp[j])cnt[j]--;
                   if(!cnt[j])cur--;
              }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

posted @ 2019-03-24 23:26  czy-power  阅读(310)  评论(0编辑  收藏  举报