题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream> #include <sstream> #include <string> #include <vector> #include <cctype> using namespace std; int main() { string sentence, word; vector<string> words; getline(cin, sentence); for(auto &ch:sentence) if(!isalnum(ch)) ch = ' '; stringstream ss; ss << sentence; while(ss >> word) words.push_back(word); for(auto it=words.rbegin();it != words.rend();it++) cout << *it << " "; } // 64 位输出请用 printf("%lld")