#include <iostream>
#include <fstream>
#include <cctype>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "");
if (argc == 1)
{
std::cout << "Не введен аргумент командной строки!" << std::endl;
return 1;
}
std::ifstream fin(argv[1]);
if (!fin.is_open())
{
std::cout << "Не удалось открыть файл!" << std::endl;
return 1;
}
std::string str;
const char *delimit = ".,!?1234567890-=+#% \t";
std::map<std::string, size_t> words;
while (std::getline(fin, str))
{
for (std::string::size_type pos = 0; (pos = str.find_first_not_of(delimit, pos)) != std::string::npos;)
{
std::string::size_type n = pos;
pos = str.find_first_of(delimit, pos);
std::string word = str.substr(n, pos == std::string::npos ? pos : pos - n);
for (char &c : word)
c = std::tolower((unsigned char)c);
++words[word];
}
}
fin.close();
std::map<std::string, size_t>::iterator it;
for (it = words.begin(); it != words.end(); ++it)
{
std::cout << (it->first.c_str()) << " - " << it->second << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGNjdHlwZT4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxhbGdvcml0aG0+CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciogYXJndltdKQp7CglzZXRsb2NhbGUoTENfQUxMLCAiIik7CgoJaWYgKGFyZ2MgPT0gMSkKCXsKCQlzdGQ6OmNvdXQgPDwgItCd0LUg0LLQstC10LTQtdC9INCw0YDQs9GD0LzQtdC90YIg0LrQvtC80LDQvdC00L3QvtC5INGB0YLRgNC+0LrQuCEiIDw8IHN0ZDo6ZW5kbDsKCQlyZXR1cm4gMTsKCX0KCXN0ZDo6aWZzdHJlYW0gZmluKGFyZ3ZbMV0pOwoJCglpZiAoIWZpbi5pc19vcGVuKCkpCgl7CgkJc3RkOjpjb3V0IDw8ICLQndC1INGD0LTQsNC70L7RgdGMINC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