首页 > 其他 > 详细

Reverse Words in a String

时间:2015-06-21 18:21:23      阅读:151      评论:0      收藏:0      [点我收藏+]

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     }

 

Reverse Words in a String

原文:http://www.cnblogs.com/happygirl-zjj/p/4592182.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!