-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArt of Balance.cpp
43 lines (37 loc) · 1.17 KB
/
Art of Balance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int alpha[27];
int main()
{
string s;
int tcase;
cin>>tcase;
while(tcase--)
{
cin>>s;
int tsize=s.size();
for(int i=0; i<tsize; i++)
alpha[s[i]-'A']++;
sort(alpha,alpha+26,greater<int>());
int temp=0,minimum=INT_MAX;
for(int i=0; i<26; i++)
{
int j=i+1;
if(tsize%j==0)
{
int tdivide=tsize/j;
int total=0;
for(int M=0; M<=i; M++)
{
if(alpha[M]<tdivide)
total+=abs(alpha[M]-tdivide);
}
if(minimum>total)
minimum=total;
}
}
cout<<minimum<<endl;
memset(alpha,0,sizeof(alpha));
}
return 0;
}