Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int arr[26];
  4. int main() {
  5. int n,k,x,count = 1,mx = 0,c;
  6. string str;
  7. cin >> n >> k >> str;
  8. if(k == 1){
  9. for(int i = 0;i < n;i++){
  10. c = str[i] - 97;
  11. arr[c]++;
  12. mx = max(mx,arr[c]);
  13. }
  14. }
  15. else{
  16. for(int i = 0;i < n - 1;i++){
  17. if(str[i] == str[i + 1]){
  18. count++;
  19. if(count == k){
  20. c = str[i] - 97;
  21. arr[c]++;
  22. mx = max(mx,arr[c]);
  23. count = 1;
  24. i++;
  25. }
  26.  
  27. }
  28. else if(count > 1)
  29. count = 1;
  30. }
  31. }
  32. cout << mx;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement