Zuhair and Strings

Zuhair and Strings

Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string ss has a level xx, if xx is largest non-negative integer, such that it’s possible to find in ss:

xx non-intersecting (non-overlapping) substrings of length kk,
all characters of these xx substrings are the same (i.e. each substring contains only one distinct character and this character is the same for all the substrings).
A substring is a sequence of consecutive (adjacent) characters, it is defined by two integers ii and jj (1≤i≤j≤n1≤i≤j≤n), denoted as s[i…j]s[i…j] = “sisi+1…sjsisi+1…sj”.

For example, if k=2k=2, then:

the string “aabb” has level 11 (you can select substring “aa”),
the strings “zzzz” and “zzbzz” has level 22 (you can select two non-intersecting substrings “zz” in each of them),
the strings “abed” and “aca” have level 00 (you can’t find at least one substring of the length k=2k=2 containing the only distinct character).
Zuhair gave you the integer kk and the string ss of length nn. You need to find xx, the level of the string ss.

Input
The first line contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the length of the string and the value of kk.

The second line contains the string ss of length nn consisting only of lowercase Latin letters.

Output
Print a single integer xx — the level of the string.

Examples
Input
8 2
aaacaabb
Output
2
Input
2 1
ab
Output
1
Input
4 2
abab
Output
0
//小写字母减97可以得到是第几个字母。大写字母减65//

#include<stdio.h>
int main()
{
	int n, k,i;
	char s[200002];
	int a[26] = { 0 }, f = 1;
	scanf("%d%d", &n, &k);
	getchar();
	gets(s);
	if (k == 1)
	{
		for (i = 0; i < n; i++)
		{
			a[s[i] - 97]++;
		}
	}
	else
	{
		for (i = 1; i < n; i++)
		{
			if (s[i] == s[i - 1])
			{
				f++;
				if (f == k)
				{
					a[s[i] - 97]++;
					f = 1;
					i++;

				}
				if (f != k && s[i] != s[i + 1]) f = 1;
			}
			
		}
	}
	int max = 0;
	for (i = 0; i < 26; i++)
	{
		if (a[i] > max) max = a[i];
	}
	printf("%d", max);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值