Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <unordered_set>
- using namespace std;
- string readInput()
- {
- string result;
- int numberOfLines;
- cin >> numberOfLines;
- cin.ignore();
- for (int i = 0; i < numberOfLines; i++)
- {
- string line;
- getline(cin, line);
- result = result + line + " ";
- }
- return result;
- }
- void cleanSentence(string &text)
- {
- istringstream istr(text);
- unordered_set<string> set;
- string outText;
- do {
- string word;
- istr >> word;
- while (set.find(word) == set.end())
- {
- outText = outText + word + " ";
- set.insert(word);
- }
- } while (istr);
- outText.erase(outText.size() - 1);
- cout << outText;
- }
- void makeSentence(string &text)
- {
- istringstream istr(text);
- string word;
- string output;
- while (istr >> word)
- {
- output = output + word + " ";
- if (word == "." )
- {
- cleanSentence(output);
- output = "";
- }
- }
- cleanSentence(output);
- }
- int main()
- {
- string inputText = readInput();
- makeSentence(inputText);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment