标签:
Description:
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
Code:
1 void reverseWords(string &s) { 2 istringstream sstr(s); 3 s = ""; 4 string str; 5 bool flag = true; 6 while (sstr>>str) 7 { 8 if (flag) 9 { 10 s = str + s; 11 flag = false; 12 } 13 else 14 s = str + ‘ ‘ + s; 15 } 16 }
标签:
原文地址:http://www.cnblogs.com/happygirl-zjj/p/4592182.html