string

来源:互联网 发布:微信刷赞软件破解版 编辑:程序博客网 时间:2024/06/07 23:17

Boring count

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1659    Accepted Submission(s): 611


Problem Description
You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.
 

Input
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.

[Technical Specification]
1<=T<= 100
1 <= the length of S <= 100000
1 <= K <= 100000
 

Output
For each case, output a line contains the answer.
 

Sample Input
3abc1abcabc1abcabc2
 

Sample Output
61521

#include<iostream>#include<string.h>using namespace std;char s[100005];int flag[100005];int main(){int t;cin>>t;while(t--){memset(flag,0,sizeof(flag));int pos=0,k,i,j;long long count=0;cin>>s;cin>>k;for(i=0;s[i]!='\0';i++){flag[s[i]-'a']++;if(flag[s[i]-'a']>k){while(s[pos]!=s[i]){flag[s[pos]-'a']--;pos++;}flag[s[pos]-'a']--;pos++;}count+=i+1-pos;}cout<<count<<endl;}}




原创粉丝点击