class Solution {
public:
    string ReverseSentence(string str) {
        //用ss把每个单词压入数组
        if(str.length() <= 1) return str;
        vector<string> vec;
        string res;
        stringstream ss(str);
        string temp;
        while(ss>>temp){
            vec.push_back(temp);
        }
        //反着输出
        for(auto it = vec.rbegin(); it != vec.rend(); it++){
            res += *it;
            res += ' ';
        }
        res.back() = '\0';
        return res;
    }
};