B. Zuhair and Strings
题意:给出长度为n的字符串,水平为k
当k=2时,就是两个相同字符重复 “aa bb cc dd ......”
当k=3时,就是三个相同的字符重复
题目就是让求给定字符串中有多少个相同的(k个相同字符)字符。求解的过程中,相邻字符不重复。
k=2 aaacaabb 有2个相同的aa(其中a都是2个)。
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
using namespace std;
const int maxn=200010;
int n,k,ans;
char str[maxn];
int main()
{
scanf("%d%d",&n,&k);
scanf("%s",str);
ans=0;
for(int i=0;i<26;i++)
{
char x=char(i+'a');
int res=0 ,cnt=0;
for(int j=0;j<n;j++)
{
if(str[j]!=x)
{
int y=cnt/k;
res=res+y;
cnt=0;
}else
cnt++;
}
int y=cnt/k;
res=res+y;
ans=max(res,ans);
}
printf("%d\n",ans);
return 0;
}