Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string str;
- int len;
- int diffChar(int sz){
- int cnt = 0;
- for(int i = 0; i < sz; ++i){
- int charCnt[27] = {};
- int mx = 0;
- for(int j = i; j < len; j += sz){
- ++charCnt[str[j] - 'a'];
- mx = max(mx, charCnt[str[j] - 'a']);
- }
- cnt += len / sz - mx;
- }
- return cnt;
- }
- int main(){
- cin >> str;
- len = str.size();
- int upBound = sqrt(len);
- int mn = len;
- for(int i = 1; i <= upBound; ++i){
- if(len % i == 0){
- mn = min(mn, diffChar(i));
- if(i != 1 && i != len / i){
- mn = min(mn, diffChar(len / i));
- }
- }
- }
- cout << mn;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement