Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
class Solution {
public:
void reverseWords(string &s) {
string word;
stack<string> buf;
stringstream ss(s);
while(ss>>word)
{
buf.push(word);
}
string res = "";
bool first = true;
while(!buf.empty())
{
if(!first)
res += " ";
res += buf.top();
buf.pop();
first = false;
}
s = res;
}
};【LeetCode】Reverse Words in a String,布布扣,bubuko.com
【LeetCode】Reverse Words in a String
原文:http://blog.csdn.net/xiaozhuaixifu/article/details/21296879