LINUX.ORG.RU

История изменений

Исправление Siborgium, (текущая версия) :

Эту несложную программу лучше на С++ переписать.

#include <iostream>
#include <map>
#include <string>

int main() {
    std::map<std::string, unsigned> words;
    for (std::string word; std::cin >> word;) {
        auto [iter, emplaced] = words.try_emplace(std::move(word), 1);
        iter->second += !emplaced;
    }
    for (auto& [word, count] : words) {
        std::cout << word << ' ' << count << '\n';
    }
}

Исходная версия Siborgium, :

Эту несложную программу лучше на С++ переписать.

#include <iostream>
#include <map>
#include <string>

int main() {
    std::map<std::string, unsigned> words;
    for (std::string word; std::cin >> word;) {
        auto [iter, emplaced] = words.try_emplace(std::move(word), 0);
        iter->second += !emplaced;
    }
    for (auto& [word, count] : words) {
        std::cout << word << ' ' << count << '\n';
    }
}