#include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
string sentence = "house tree car";
cout << "original string: " << sentence;
istringstream iss(sentence);
vector<string> tokens;
copy(istream_iterator<string>(iss),
istream_iterator<string>(),
back_inserter< vector<string> >(tokens));
cout << "\n new string: ";
for (int i = tokens.size() - 1; i >= 0; i--)
{
cout << tokens[i] << ' ';
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkKewogICAgc3RyaW5nIHNlbnRlbmNlID0gImhvdXNlIHRyZWUgY2FyIjsKICAgIAogICAgY291dCA8PCAib3JpZ2luYWwgc3RyaW5nOiAiIDw8IHNlbnRlbmNlOwogICAgCiAgICBpc3RyaW5nc3RyZWFtIGlzcyhzZW50ZW5jZSk7CiAgICB2ZWN0b3I8c3RyaW5nPiB0b2tlbnM7CiAgICBjb3B5KGlzdHJlYW1faXRlcmF0b3I8c3RyaW5nPihpc3MpLAogICAgICAgICBpc3RyZWFtX2l0ZXJhdG9yPHN0cmluZz4oKSwKICAgICAgICAgYmFja19pbnNlcnRlcjwgdmVjdG9yPHN0cmluZz4gPih0b2tlbnMpKTsKICAgIAogICAgY291dCA8PCAiXG4gICAgIG5ldyBzdHJpbmc6ICI7CiAgICBmb3IgKGludCBpID0gdG9rZW5zLnNpemUoKSAtIDE7IGkgPj0gMDsgaS0tKQogICAgewogICAgICAgIGNvdXQgPDwgdG9rZW5zW2ldIDw8ICcgJzsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==