#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string*> uniqueWords;
vector<string*> document;
string word;
while (cin >> word && word != "STOP")
{
string* foundPtr = nullptr;
for (string* ptr : uniqueWords)
{
if (*ptr == word)
{
foundPtr = ptr;
break;
}
}
if (foundPtr == nullptr)
{
string* newWord = new string(word);
uniqueWords.push_back(newWord);
document.push_back(newWord);
}
else
{
document.push_back(foundPtr);
}
}
for (string* ptr : document)
{
cout << *ptr << " ";
}
cout << endl;
for (string* ptr : uniqueWords)
{
cout << *ptr << " " << ptr << endl;
}
for (string* ptr : uniqueWords)
{
delete ptr;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: