Can anybody please check why WA is coming?


#1
unordered_map<string,int>m;
vector<string> split(string str, char ch){
    vector<string> s;
    // cout<<str<<"----\n";
    int i;
    int s_index =0, e_index=0;
    for(i=1;i<str.size();i++){
        if(str[i]==ch){
            e_index =i-s_index;
            string temp =str.substr(s_index,e_index);
            // cout<<s_index<<" "<<e_index<<" "<<temp<<"\n";
            s.push_back(temp);
            s_index=i+1;
        }
    }
    if(s_index<str.size())
    {   string temp = str.substr(s_index,str.size()-s_index);
        // cout<<"------------"<<s_index<<temp<<"\n";
        s.push_back(temp);}
    return s;
}
    int comp( pair<string,int> a, pair<string,int> b ){
        
        vector<string>ar;
        vector<string>br;
        ar = split(a.first,'_');
        br= split(b.first,'_');
        // string ar[]=a.first.split("_");
        // string br[]=b.first.split(" ");
        int i;
        int count_a=0,count_b=0;
        for(i=0;i<ar.size();i++){
            if(m.find(ar[i])!=m.end())
             count_a++;
        }    
        // cout<<a.first<<" "<<count_a<<"\n";
        for(i=0;i<br.size();i++){
            if(m.find(br[i])!=m.end())
             count_b++;
        }   
            //   cout<<b.first<<" "<<count_b<<"\n";
        return count_a>count_b;
    }
    
vector<int> Solution::solve(string A, vector<string> &B) {
    int i;
    vector<string>ans;
    ans = split(A,'_');
    // string ans[]=A.split("_");
    for(i=0;i<ans.size();i++){
        // cout<<ans[i]<<" - ";
        m[ans[i]]++;
    }
    vector<pair<string,int> >v;
    for(i=0;i<B.size();i++){
        // B[i].trim();
        v.push_back(make_pair(B[i],i));
    }
    stable_sort(v.begin(),v.end(),comp);
    vector<int>temp;
    for(i=0;i<v.size();i++){
        temp.push_back(v[i].second);
    }
    return temp;
    
    
}