#include <string> // for storing strings in a C++ way
#include <sstream> // to easily separate sentences into words
#include <vector> // to dynamically store arbitrary amounts of words
#include <algorithm> // for std::reverse
#include <iostream> // for printing the result
int main()
{
std::string sentence = "Your sentence which contains ten words, two of them numbers";
std::stringstream stream(sentence);
std::string word;
std::vector<std::string> words;
while ( stream >> word )
{
words.push_back(word);
}
std::reverse(words.begin(), words.end());
for ( size_t i(0); i < words.size(); ++i )
{
std::cout << words[i] << " ";
}
std::cout << "\n";
}
CiNpbmNsdWRlIDxzdHJpbmc+IC8vIGZvciBzdG9yaW5nIHN0cmluZ3MgaW4gYSBDKysgd2F5CiNpbmNsdWRlIDxzc3RyZWFtPiAvLyB0byBlYXNpbHkgc2VwYXJhdGUgc2VudGVuY2VzIGludG8gd29yZHMKI2luY2x1ZGUgPHZlY3Rvcj4gLy8gdG8gZHluYW1pY2FsbHkgc3RvcmUgYXJiaXRyYXJ5IGFtb3VudHMgb2Ygd29yZHMKI2luY2x1ZGUgPGFsZ29yaXRobT4gLy8gZm9yIHN0ZDo6cmV2ZXJzZQojaW5jbHVkZSA8aW9zdHJlYW0+IC8vIGZvciBwcmludGluZyB0aGUgcmVzdWx0CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6c3RyaW5nIHNlbnRlbmNlID0gIllvdXIgc2VudGVuY2Ugd2hpY2ggY29udGFpbnMgdGVuIHdvcmRzLCB0d28gb2YgdGhlbSBudW1iZXJzIjsKICAgIHN0ZDo6c3RyaW5nc3RyZWFtIHN0cmVhbShzZW50ZW5jZSk7CiAgICBzdGQ6OnN0cmluZyB3b3JkOwogICAgc3RkOjp2ZWN0b3I8c3RkOjpzdHJpbmc+IHdvcmRzOwogICAgd2hpbGUgKCBzdHJlYW0gPj4gd29yZCApCiAgICB7CiAgICAgICAgd29yZHMucHVzaF9iYWNrKHdvcmQpOwogICAgfQogICAgc3RkOjpyZXZlcnNlKHdvcmRzLmJlZ2luKCksIHdvcmRzLmVuZCgpKTsKICAgIGZvciAoIHNpemVfdCBpKDApOyBpIDwgd29yZHMuc2l6ZSgpOyArK2kgKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCB3b3Jkc1tpXSA8PCAiICI7CiAgICB9CiAgICBzdGQ6OmNvdXQgPDwgIlxuIjsKfQo=