Advertisement
Alhiris

Untitled

Jan 20th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define maxn 200005
  4.  
  5. int n,k;
  6. char a[maxn];
  7. int sol[30];
  8. int counter[30];
  9.  
  10. int main()
  11. {
  12.     int i,k,rez=0;
  13.     cin>>n>>k;
  14.     cin>>a;
  15.     if(k>1)
  16.         for(i=0;i<n-1;++i){
  17.             if(a[i]==a[i+1]){
  18.                 counter[a[i]%26]++;
  19.                 if(counter[a[i]%26]==(k-1))
  20.                     ++sol[a[i]%26],counter[a[i]%26]=0,++i;
  21.             }else
  22.                 counter[a[i]%26]=0;
  23.         }
  24.     else
  25.         for(i=0;i<n;++i)
  26.             ++sol[a[i]%26];
  27.  
  28.     for(i=0;i<28;++i)
  29.         if(sol[i]>rez)
  30.             rez=sol[i];
  31.     cout<<rez;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement