首页 > 代码库 > Reverse Words in a String

Reverse Words in a String

Reverse Words in a String

反转一个字符串

垃圾方法:

#include <sstream>
#include <vector>

class Solution {
public:
    void reverseWords(string &s) {
        istringstream is(s);
        string word;
        vector<string> dict;
        while (is >> word) {
            dict.push_back(word);
        }
        string ret = "";
        for (int i = dict.size() - 1; i > 0; --i) {
            ret = ret + dict[i] + " ";
        }
        if (dict.size() > 0)
            ret += dict[0];
        s = ret;
    }
};
View Code

 

Evaluate Reverse Polish Notation

简单计算器