include
include
include
using namespace std;
class StrTools {
public:
string reverseWords(string s) {
stringstream all(s);
string word = "", res = "";
while (all >> word) {
res = word + " " + res;
}
return res.substr(0, res.size() - 1);
}
string reverseWords2(string s) {
std::reverse(begin(s), end(s));
stringstream all(s);
string word = "", res = "";
while (all >> word) {
std::reverse(begin(word), end(word));
res = res + " " + word;
}
return res.empty() ? "" : res.substr(1);
}
};
int main() {
string str="Hello, World!";
StrTools st;
std::cout << st.reverseWords(str.c_str()) << std::endl;
std::cout << st.reverseWords2(str.c_str()) << std::endl;
return 0;
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询