题解 | #倒置字符串#C++解法,通过reverse逆置
倒置字符串
https://www.nowcoder.com/practice/ee5de2e7c45a46a090c1ced2fdc62355
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string s; getline(cin, s); reverse(s.begin(), s.end()); auto start = s.begin(); while(start != s.end()) { auto end = start; while(end != s.end() && *end != ' ') { end++; } reverse(start, end); if(end != s.end()) { start = end + 1; } else { start = end; } } cout << s << endl; return 0; }