题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main() { string ss; vector<string> vct; string buf = ""; getline(cin, ss); for (auto cc : ss) { if ((cc >= 'A' && cc <= 'Z') || (cc <= 'z' && cc >= 'a')) { buf.push_back(cc); continue; } else { vct.push_back(buf); buf.clear(); continue; } } vct.push_back(buf); vector<string>::reverse_iterator it = vct.rbegin(); for (; it != vct.rend(); it++) { cout << *it << " "; } return 0; }