将一组单词逆序输出

#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
int main(){
string str;

while(getline(cin,str))
{
vector<string> array;
string temp;
for(auto i=0;i<str.size();i++)
{
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
temp+=str[i];
else{
array.push_back(temp);
temp.clear();
}
}

vector<string>::reverse_iterator it=array.rbegin();
while(it!=array.rend())
{
cout<<*it<<" ";
++it;
}
cout<<endl;
}
system("pause");
return 0;
}

posted on 2017-05-22 22:51  zhaodun  阅读(425)  评论(0编辑  收藏  举报

导航