i wanted to use a hash map to sort a string on the basis of the values the map has.but i just could not find a suitable way..please help me find a way. so here is a c++ code that I wrote please help me how to write it better i want to know how to use std::sort() by passing a data structure for sorting
#include<bits/stdc++.h>
using namespace std;
unordered_map<char,int>m;
bool h(char a,char b)
{
return m[a]<=m[b];
}
int main()
{
int t;
cin>>t;
while(t--)
{
//unordered_map<char,int>m;
for(int i=1;i<=26;i++)
{
char a;
cin>>a;
m[a]=i;
}
string s;
cin>>s;
sort(s.begin(),s.end(),h);
cout<<s<<endl;
//m.erase(m.begin(),m.end());
//cout<<endl<<m.size();
}
}