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
3
abc
1
abcabc
1
abcabc
2
Sample Output
6
15
21
此題允許不同位置上的相同字母算作不同種類
雙指針(也叫窗口滑動(也叫尺取法)):
定義兩個指針,始終保持指針內的子串符合題目要求,向右移動右指針,若不符合要求,則將左指針向右移動直到指針內的子串符合題目要求為止。這樣就求出了每個點向左延伸最遠符合要求的點,於是這個區間內的任意一個子串都是符合題目要求的,不斷累加即可。
復雜度:O(n).
#include
#include
#include
#include
#include