#include <unordered_map>
#include <string>
#include <iostream>
+#include <typeinfo>
typedef std::unordered_map<std::string, int> hash_t;
-
int main()
{
std::cin.sync_with_stdio(false);
}
}
- std::vector<const std::string*> words(hash.size());
- int i = 0;
+ std::vector<std::string> words;
for (const auto& e : hash) {
- words[i++] = &(e.first);
- // words.push_back(&(e.first));
+ words.push_back(e.first);
}
- std::sort(words.begin(), words.end(), [&hash] (const std::string* a, const std::string* b) -> bool {
- int diff = hash[*a] - hash[*b];
- return (diff < 0) || (diff == 0 && (*a) < (*b)); // (a.compare(b) < 0);
+ std::sort(words.begin(), words.end(), [&hash] (const std::string& a, const std::string& b) -> bool {
+ int diff = hash[a] - hash[b];
+ return (diff < 0) || (diff == 0 && a < b); // (a.compare(b) < 0);
});
- for (const auto e : words) {
- std::cout << *e << " " << hash[*e] << "\n";
+ for (const auto& e : words) {
+ std::cout << e << " " << hash[e] << "\n";
}
}