Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- #include <map>
- #include <Windows.h>
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- std::ifstream fin("file.txt");
- if (!fin.is_open()) {
- std::cout << "Ошибка открытия файла" << std::endl;
- }
- else {
- std::string str;
- std::map<std::string, int> dictionary;
- while (!fin.eof()) {
- fin >> str;
- while (str.size() > 0 && (str[0] < 'А' || str[0] > 'я')) {
- str.erase(str.begin());
- }
- while (str.size() > 0 && (str.back() < 'А' || str.back() > 'я')) {
- str.pop_back();
- }
- if (str.size() > 0) {
- for (char& ch : str) { // если не нужен перевод в нижний регистр, то можно не делать
- if (ch >= 'А' && ch <= 'Я') {
- ch += 32;
- }
- }
- dictionary[str]++;
- }
- }
- for (auto a : dictionary) {
- std::cout << a.first << " " << a.second << std::endl;
- }
- fin.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment