Advertisement
Lavig

Другий семестр. Лабораторна робота №4 (Завдання 2)

Feb 22nd, 2025 (edited)
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     setlocale(0, "Ukrainian");
  12.     SetConsoleOutputCP(1251);
  13.     SetConsoleCP(1251);
  14.     string text{}, temp_word{};
  15.     vector<string> all_words;
  16.     string word;
  17.     int i{};
  18.     cout << "Введіть будь-який текст: " << endl;
  19.     getline(cin, text);
  20.     text.erase(remove_if(text.begin(), text.end(), ispunct), text.end());
  21.     transform(text.begin(), text.end(), text.begin(), tolower);
  22.     for (i = 0; i < text.size(); i++) {
  23.         if (text[i] != ' ') {
  24.             word += text[i];
  25.         }
  26.         else {
  27.             all_words.push_back(word);
  28.             word = "";
  29.         }
  30.     }
  31.     all_words.push_back(word);
  32.     sort(begin(all_words), end(all_words));
  33.     auto iterator = unique(all_words.begin(), all_words.end());
  34.     all_words.resize(distance(all_words.begin(), iterator));
  35.     cout << "Список всіх унікальних слів у лексикографічному порядку: " << endl;
  36.     for (i = 0; i < all_words.size(); i++) {
  37.         if (all_words[i] != "") {
  38.             cout << all_words[i] << endl;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement