HRusev

Letters

Jun 20th, 2023
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <memory>
  5. #include <algorithm>
  6. #include <cctype>
  7. #include <vector>
  8. #include<set>
  9. #include <ctype.h>
  10.  
  11. using namespace std;
  12.  
  13.  
  14. int main()
  15. {
  16.     vector<string> allWords;
  17.  
  18.     string line;
  19.     getline(cin, line);
  20.  
  21.     for (char& c : line)
  22.         if (!(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'))
  23.             c = ' ';
  24.  
  25.     istringstream istr(line);
  26.     string curEl;
  27.  
  28.    
  29.  
  30.     while (istr >> curEl)
  31.     {
  32.         allWords.push_back(curEl);
  33.     }
  34.  
  35.     char letter;
  36.     cin >> letter;
  37.     cin.ignore();
  38.  
  39.     while (letter != '.')
  40.     {
  41.         set<string> forPrint;
  42.  
  43.  
  44.         for (size_t i = 0; i < allWords.size(); i++)
  45.         {
  46.             string originalWord = allWords[i];
  47.             string testCopy = originalWord;
  48.  
  49.             string* upperWord = &testCopy;
  50.  
  51.  
  52.             transform(upperWord->begin(), upperWord->end(), upperWord->begin(), ::toupper);
  53.  
  54.  
  55.             char upperSym = toupper(letter);
  56.  
  57.             size_t found = testCopy.find_first_of(upperSym);
  58.  
  59.             if (found != std::string::npos)
  60.             {
  61.                 forPrint.insert(originalWord);
  62.             }
  63.  
  64.         }
  65.  
  66.         if (forPrint.empty())
  67.         {
  68.             cout << "---" << endl;
  69.  
  70.         }
  71.         else
  72.         {
  73.             set<string>::iterator itr;
  74.  
  75.             for (itr = forPrint.begin(); itr != forPrint.end(); itr++)
  76.             {
  77.                 cout << *itr << " ";
  78.             }
  79.  
  80.             cout << endl;
  81.  
  82.         }
  83.  
  84.  
  85.         cin >> letter;
  86.         cin.ignore();
  87.     }
  88.  
  89.  
  90.     cout << endl;
  91.  
  92.     return 0;
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment