码迷,mamicode.com
首页 > 其他好文 > 详细

Reverse Words in a String

时间:2015-06-21 18:21:31      阅读:113      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!