# Help me in solving CFMM problem

### My code

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int freq,i,j,k,l,m,n,o,p,q,t,u,v,w,x;
cin>>freq;
for (i=0;i<freq;i++)
{
cin>>j;
string s;
string arr;
arr.assign(26,0);
for (k=0;k<j;k++)
{
cin>>s;
for (l=0;l<s.size();l++)
{
arr[s[l]-'a']++;
}
}
m=arr;
n=arr['c'-'a'];
o=arr['d'-'a'];
p=arr['e'-'a'];
q=arr['h'-'a'];
t=arr['f'-'a'];
w=n/2;
x=p/2;
u=min(min(min(min(min(m,o),q),t),w),x);
cout<<u<<endl;
arr.assign(26,0);

}
return 0;
}

``````

Problem Link: CFMM Problem - CodeChef

@abishek_1111
Your logic is not right bro.
plzz refer the following solution for the better understanding of the logic.

``````#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,cnt=0;
cin>>n;
//number of strings input.
int a;
map<char,int> m;
m['c']=0;
m['o']=0;
m['d']=0;
m['e']=0;
m['h']=0;
m['f']=0;
//string input.
for(int i=0;i<n;i++){
string s;
cin>>s;
//counting frequency of letters.
for(int j=0;j<s.size();j++){
char x =s[j];
m[x]++;
}
}				for(auto it : m){
if(it.first =='o' || it.first =='d' || it.first =='h' || it.first =='f'){
a[cnt] = it.second;
cnt++;
}
else if(it.first == 'c' || it.first =='e'){
a[cnt] = it.second/2;
cnt++;
}
else{
continue;
}
}
sort(a,a+cnt);
cout<<a<<endl;

}
}
``````
1 Like