Meng xin eat fruit fruit
Description
The first day of school, Meng new to row and eat fruit, Ki asked the new students sit in a row.
Now the Moe must be seated one by one, according to Ki's order form.
Meng Xin includes boys, girls and help her.
The boy will not hesitate to sit in the seat of the person who is currently seated, the girl in the seat will be seated with the front of the * * * * * * * * * * * * * * * * * * * * * *, and help her to observe the number of consecutive sitting, if the number is equal to the degree of psychological tolerance $k$, then help
So the question is, Ki wants to know at least how many chairs are needed to make these new, just sit in a row. Input
The first line has an integer $t$ that represents the number of groups tested.
Next, each test group entered the first line $n, k$, representing the total number of people, and helped her psychological tolerance.
The second line enters a string of length $n$, representing the order table of Ki. The string consists of $ A, B, C $ three strings, each referring to the boy, the girl, and help her.
Data range: T <= 1, <= n,k <=100000 Output
For each test group output line, indicates the minimum number of chairs required. Sample Input
2
6 2
aaabcc
8 3
Abbccbaa
Sample Output
8
10
HINT
For example, the first set of data in the sample, AAABCC, and k = 2, the last seat to sit as follows, requires 8 seats
Aaa_bc_c
Original title Link: http://oj.acm.zstu.edu.cn/JudgeOnline/problem.php?id=4246 code example:
#include <stdio.h>
#include <string.h>
const int maxn=1e5+10;
Char S[MAXN];
int main ()
{
int t;
scanf ("%d", &t);
while (t--)
{
memset (S, ' n ', sizeof (s));
int n,k,i;
scanf ("%d%d%s", &n,&k,s);
int Len=strlen (s);
int cnt=0,ans=0,last=0;
for (i=0;i<len;i++)
{
if (s[i]== ' a ')
{
last=1;ans++;
}
if (s[i]== ' B ')
{
if (last==1)
{
ans++;
cnt=0;
}
ans++;
last=0;
}
if (s[i]== ' C ')
{
last=0;
if (cnt>=k)
{
ans++;
cnt=0;
}
ans++;
}
cnt++;
}
printf ("%d\n", ans);
}
return 0;
}
PS: Nothing to say, mainly is the flexible use of tag variables, their own write a other method unexpectedly timeout.