面試寶典——將一句話里的單詞進行倒置,標點符號不倒置


 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM