#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

vector<pair<string,string>> KeySort(map<string,string> s, const vector<string>& order){
    vector<pair<string,string>> res;
    for (const auto& it : order) {
        auto needle = s.find(it);
        if(needle != s.end()){
            res.emplace_back(move(*needle));
            s.erase(needle);
        }
    }
    for (auto&& it : s) res.emplace_back(move(it));
    return res;
}

int main() {
    // create vector holding desired ordering
    vector<string> ord({ "a", "d", "i", "n", "ns", "ne", "vl", "rr" });
    
    // create the map
    map<string,string> MyMap = { {"a","legato"}, {"vl","4"}, {"i","2"}, {"rr","3"}, {"z","unspecified1"}, {"b","unspecified2"}};

    // sort the vector
    vector<pair<string,string>> out = KeySort(MyMap, ord);

    // put the vector pairs into a string format
    for (auto& it : out) cout << it.first << "=" << it.second << " ";

    return 0;
}