Advertisement
Josif_tepe

Untitled

Oct 10th, 2021
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     int n, period;
  9.     cin >> n >> period;
  10.     int bukvi[26];
  11.     string s;
  12.     cin >> s;
  13.     int res = 0;
  14.     for(int i = 0; i < period; i++) {
  15.         for(int j = 0; j < 26; j++) {
  16.             bukvi[j]  = (n / period);
  17.         }
  18.         for(int j = i; j < n; j += period) {
  19.             bukvi[s[j] - 'A']--;
  20.         }
  21.         int najmal_element = 2e9;
  22.         for(int j = 0; j < 26; j++) {
  23.             if(najmal_element > bukvi[j]) {
  24.                 najmal_element = bukvi[j];
  25.             }
  26.         }
  27.         res += najmal_element;
  28.     }
  29.     cout << res << endl;
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement