链接:https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/solution/yi-ge-mo-ban-shua-bian-suo-you-zi-fu-chu-x6vh/
来源:力扣(LeetCode)
string reverseWords(string s) {
s+=" ";
string temp ="";
vector<string>res;
for(char c:s)
{
if(c==' ')
{
if(!temp.empty())
{
res.push_back(temp);
temp.clear();
}
}
else temp+=c;
}
reverse(res.begin(),res.end());
for(auto str:res)
{
temp+=str+' ';
}
temp.pop_back();
return temp;
}