标签:style blog http color strong for
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
class Solution { public: void reverseWords(string &s) { int nLen=s.size(); if(nLen<=0) return; string temp,result; int index=0; while(s[index]==‘ ‘) index++; for(int i=index;i<nLen;) { if(s[i]!=‘ ‘) { temp+=s[i]; i++; } else { while(s[i]==‘ ‘) i++; if(i==nLen) break; result=" "+temp+result; temp=""; } } s=temp+result; } };
Reverse Words in a String,布布扣,bubuko.com
标签:style blog http color strong for
原文地址:http://www.cnblogs.com/awy-blog/p/3830810.html