Easy soln using two maps without Trie


#1
vector<string> strtolist(string &A){
    vector<string> s;
    string a;
    int i=0;
    while(i<A.size()){
        s.push_back(a);
        while(i<A.size() && A[i]!='_'){
            s[s.size()-1].push_back(A[i]);
            i++;
        }
        i++;
    }
    return s;
}
vector<int> Solution::solve(string A, vector<string> &B) {
    map<string,int> m;
    map<int,vector<int>> m1;
    vector<string> s;
    vector<int> ans;
    s=strtolist(A);
    int i;
    for(i=0;i<s.size();i++)m[s[i]]=1;
    for(i=0;i<B.size();i++){
        int score=0;
        s=strtolist(B[i]);
        for(int j=0;j<s.size();j++){
            if(m.find(s[j])!=m.end())score++;
        }
        m1[score].push_back(i);
    }
    for(map<int,vector<int>> ::iterator it=m1.begin();it!=m1.end();it++){
        reverse(it->second.begin(),it->second.end());
        for(i=0;i<it->second.size();i++){
            ans.push_back(it->second[i]);
        }
    }
    reverse(ans.begin(),ans.end());
    return ans;
}