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

复制代码
 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
复制代码

 

posted @   Run_For_Love  阅读(1374)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示