题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
while(getline(cin,str)){
vector<string> vec;
int start=0;
for(int i=0;i<str.size();++i){
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')){
continue;
}else{
int len = i-start;
if(len>=1)
vec.push_back(str.substr(start,i-start));
start=i+1;
}
}
vec.push_back(str.substr(start));
reverse(vec.begin(), vec.end());
for(auto it=vec.begin();it!=vec.end();++it)
cout<<*it<<" ";
}
return 0;
}