题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <iostream> #include<string> #include<vector> using namespace std; int main() { string str; vector<string> vct; string buf; getline(cin, str); string::iterator it = str.begin(); for (; it != str.end(); it++) { if (*it == ' ') { vct.push_back(buf); buf = ""; continue; } else { buf.push_back(*it); } } vct.push_back(buf); vector<string>::reverse_iterator it1 = vct.rbegin(); for (; it1 != vct.rend(); it1++) { cout << *it1 << " "; } }