Reverse Words in a String
来源:互联网 发布:java 1.7 32位官网 编辑:程序博客网 时间:2024/04/29 20:01
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
#include <iostream>#include <sstream>using namespace std;class Solution {public:void reverseWords(string &s) {istringstream istream(s);string word;stack<string> strStack;s.clear();bool first=true;while(istream>>word){strStack.push(word);}while(!strStack.empty()){word=strStack.top();strStack.pop();if(first){s.append(word);first = false;}else{s.append(" ");s.append(word);}}//cout<<s<<endl;}};
0 0
- Reverse words in a string.
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- Reverse Words in a String
- 实验二 数据结构——线性表的实验
- Sort List
- 十六进制字符串和byte数组的相互转化
- Flume-NG中用到的一些好的文章
- 递推 数字三角形
- Reverse Words in a String
- 学习Unity3D第六天之脚本入门例题详解。
- hdu 5091 Beam Cannon(线段树)
- arm指令MOV和ldr的区别
- fabric --- Python中的批量远程管理和部署工具
- 第十三周项目6-体验文件操作 5
- 照片墙功能
- 同系统模块通过多线程使用异步调用
- 学习Unity3D第七天之综合例题解析。