#include #include #include #include #include #include using namespace std; int main() { vector words { istream_iterator{cin}, istream_iterator{} }; map freq; for_each(begin(words), end(words), [&freq](string word){freq[word]++;}); vector> v {begin(freq), end(freq)}; sort(begin(v), end(v), [](auto l, auto r){return l.second > r.second;}); vector replace(10); transform(begin(v), begin(v)+10, begin(replace), [](auto p){return p.first;}); transform(begin(words), end(words), begin(words), [&replace](string word) { if(auto it = find(begin(replace), end(replace), word); it != end(replace) ) { return "$" + to_string(it-begin(replace)); } return word; }); transform(begin(replace), end(replace), ostream_iterator{cout, ";"}, [idx=0](auto w)mutable{ return "$" + to_string(idx++) + "=" + w; }); /* for ( size_t idx{}; idx < v.size(); ++idx ) { cout << "$" << idx << "=" << v[idx] << ";"; }*/ cout << '\n'; copy(begin(words), end(words), ostream_iterator{cout, " "}); }