(1)遍历
class Solution {
public:
string reverseWords(string s) {
int i=0;
string str="";
string temp="";
while(i<s.length()) {
str="";
while(i<s.length() && s[i]!=' ') {
str+=s[i];
i++;
}
i++;
if(str!="") {
if(temp=="") temp=str;
else temp=str+" "+temp;
}
}
if(temp[0]==' ') return temp.substr(1);
else return temp;
}
};