面试宝典——将一句话里的单词进行倒置,标点符号不倒置

 1 #include"iostream"
 2 #include"string"
 3 #include"vector"
 4 #include"sstream"
 5 #include"stdio.h"
 6 using namespace std;
 7 
 8 int main()
 9 {
10     string str;
11     vector<string> word;
12     string res;
13 
14     while(getline(cin,str))
15     {
16         word.clear();
17         stringstream input(str);
18         while(input>>res)
19         {
20             word.push_back(res);
21         }
22         for(int i=word.size()-1;i>0;i--)
23             cout<<word[i]<<" ";
24         cout<<word[0]<<endl;
25     }
26     return 0;
27 }
View Code
原文地址:https://www.cnblogs.com/acm-jing/p/10371113.html