mitakvd

1. Reporter

Nov 17th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <unordered_set>
  5.  
  6. using namespace std;
  7.  
  8. string readInput()
  9. {
  10.     string result;
  11.     int numberOfLines;
  12.     cin >> numberOfLines;
  13.     cin.ignore();
  14.  
  15.     for (int i = 0; i < numberOfLines; i++)
  16.     {
  17.         string line;
  18.         getline(cin, line);
  19.  
  20.         result = result + line + " ";
  21.     }
  22.     return result;
  23. }
  24.  
  25. void cleanSentence(string &text)
  26. {
  27.     istringstream istr(text);
  28.     unordered_set<string> set;
  29.     string outText;
  30.  
  31.     do {
  32.         string word;
  33.         istr >> word;
  34.  
  35.         while (set.find(word) == set.end())
  36.         {
  37.             outText = outText + word + " ";
  38.             set.insert(word);
  39.         }
  40.  
  41.     } while (istr);
  42.     outText.erase(outText.size() - 1);
  43.     cout << outText;
  44. }
  45.  
  46. void makeSentence(string &text)
  47. {
  48.     istringstream istr(text);
  49.     string word;
  50.     string output;
  51.  
  52.     while (istr >> word)
  53.     {
  54.         output = output + word + " ";
  55.         if (word == "." )
  56.         {
  57.             cleanSentence(output);
  58.             output = "";
  59.         }
  60.     }
  61.     cleanSentence(output);
  62. }
  63.  
  64. int main()
  65. {
  66.     string inputText = readInput();
  67.    
  68.     makeSentence(inputText);
  69.    
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment