标签:c style class blog code java
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 length=s.length(); if(length==0) return; string result; int index=0; while(true) { while(s[index]==‘ ‘ && index<length) index++; if(index==length) break; string word; while(s[index]!=‘ ‘ && index<length) word=word+s[index++]; if(result=="") result=word; else result=word+" "+result; } s=result; } };
Reverse Words in a String,布布扣,bubuko.com
标签:c style class blog code java
原文地址:http://www.cnblogs.com/erictanghu/p/3759729.html