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