C++ solution , very easy using stable_sort


#1

// Indexing thing can be improve using pair or something

unordered_map<string,bool>mp;
bool compare(string x , string y)
{
int cnt1=0;
int cnt2=0;
string temp="";
for(int i=0;i<x.size();i++)
{
if(x[i]==’_’)
{
if(mp.count(temp)==1) cnt1++;
temp.clear();
}else{
temp+=x[i];
}
}
if(mp.count(temp)==1) cnt1++;
temp.clear();

for(int i=0;i<y.size();i++)
{
    if(y[i]=='_')
    {
        if(mp.count(temp)==1) cnt2++;
        temp.clear();
    }else{
        temp+=y[i];
    }
}
if(mp.count(temp)==1) cnt2++;
return (cnt1>cnt2);

}

vector Solution::solve(string A, vector &v) {
mp.clear();
unordered_map<string,int>index;
index.clear();
string temp="";
for(int i=0;i<A.size();i++)
{
if(A[i]==’_’)
{
mp[temp]=true;
temp.clear();
}else{
temp+=A[i];
}
}
mp[temp]=true;
for(int i=0;i<v.size();i++)
{
index[v[i]]=i;
}
vectorB(v);
stable_sort(B.begin(),B.end(),compare);
vectorres;
for(int i=0;i<B.size();i++)
{
int z=index[B[i]];
res.push_back(z);
}
return res;

}