Reverse Words in a String
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) {
istringstream is(s);
string tmp="";
string out="";
while(is>>tmp){
tmp+=" ";
tmp+=out;
out=tmp;
}
s=out.substr(0,out.length()-1);
}
};