Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int arr[26];
- int main() {
- int n,k,x,count = 1,mx = 0,c;
- string str;
- cin >> n >> k >> str;
- if(k == 1){
- for(int i = 0;i < n;i++){
- c = str[i] - 97;
- arr[c]++;
- mx = max(mx,arr[c]);
- }
- }
- else{
- for(int i = 0;i < n - 1;i++){
- if(str[i] == str[i + 1]){
- count++;
- if(count == k){
- c = str[i] - 97;
- arr[c]++;
- mx = max(mx,arr[c]);
- count = 1;
- i++;
- }
- }
- else if(count > 1)
- count = 1;
- }
- }
- cout << mx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement