题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <cctype> #include <iostream> #include <string> using namespace std; #include<vector> #include <algorithm> int main() { string input,result; getline(cin,input); vector<string> output; for(int i=0;i<input.size();++i){ if(isalpha(input[i])){ int start = i; while(i<input.size() && isalpha(input[i])){ ++i; } output.push_back(input.substr(start,i-start)); } } reverse(output.begin(),output.end()); for(const string& str:output){ cout<<str<<' '; } }