Skip to content

Instantly share code, notes, and snippets.

@flouthoc
Created December 29, 2018 07:16
Show Gist options
  • Save flouthoc/b9aebf42b263c7f3af8c76d1a75c49e1 to your computer and use it in GitHub Desktop.
Save flouthoc/b9aebf42b263c7f3af8c76d1a75c49e1 to your computer and use it in GitHub Desktop.
challenge
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
string letters;
string target;
cin>>letters;
cin>>target;
//cout<<letters;
string result;
vector<int> tarn;
map<char, unsigned> primap;
map<unsigned , char> invmap;
string::iterator iter;
for(unsigned i=0; i<letters.length(); i++){
primap.insert(pair<char, unsigned>(letters.at(i), (unsigned)i));
invmap.insert(pair<unsigned, char>((unsigned)i, letters.at(i)));
}
for(unsigned i=0; i<target.length(); i++){
tarn.push_back(primap[target.at(i)]);
}
sort(tarn.begin(), tarn.end());
for(int i=0; i<tarn.size(); i++){
result += invmap[(unsigned)tarn[i]];
}
cout<<result;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment