https://leetcode.com/problems/reverse-words-in-a-string-iii/description/
class Solution {
public:
string reverseWords(string s) {
stack<char> st;
string str="";
for(int i=0;i<s.size();i++){
if(s[i]==' '){
while(!st.empty()){
str+=st.top();
st.pop();
}
str += ' ';
}
else st.push(s[i]);
}
while(!st.empty()){
str += st.top();
st.pop();
}
return str;
}
};