#include<stack>
class Solution {
public:
string reverseWords(string s) {
int l = s.length();
int i = 0;
string res;
stack<char> tmp;
while(i<l)
{
while(i<l&&s[i]!=' ')
{
tmp.push(s[i]);
i++;
}
while(!tmp.empty())
{
char t = tmp.top();
res+=t;
tmp.pop();
}
if(i<l)res+=' ';
i++;
}
return res;
}
};