题解 | #翻转单词序列#

翻转单词序列

http://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3

class Solution {
public:
    string ReverseSentence(string str) {
    	// 把单词压入栈中
        string x;
        stack<string> s;
        istringstream is(str);
        while(is >> x){
          s.push(x);
        }
      	
        // 出栈重组单词
        string final_str;
        while(!s.empty()){
          final_str += s.top();
          final_str += " ";
          s.pop();
        }
      
      return final_str.substr(0, final_str.length()-1);
    }
};
全部评论

相关推荐

2025-12-17 17:15
华东师范大学 运营
点赞 评论 收藏
分享
哞客37422655...:这就是真实社会,没有花里胡哨的安慰,让你感受到阶级分明,不浪费彼此时间。虽然露骨但是唉
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务