void reverseWords(string &s) {
string res = "", tmp = "";
int l = s.length();
int i = ;
while(i < l){
if(s[i] != ' ')
tmp += s[i++];
else{
if(tmp != ""){
if(res == "")
res = tmp;
else{
res = tmp + " " + res;
}
tmp = "";
}
i++;
}
}
if(res == "")
res = tmp;
else if(tmp != ""){
res = tmp + " " + res;
}
s = res;
}

Reverse Words in a String的更多相关文章

  1. [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  2. [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  3. [LeetCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  4. [LintCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...

  5. LeetCode Reverse Words in a String II

    原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, rever ...

  6. LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation

    LeetCode: Reverse Words in a String:Evaluate Reverse Polish Notation Evaluate the value of an arithm ...

  7. leetcode6 Reverse Words in a String 单词取反

    Reverse Words in a String  单词取反 whowhoha@outlook.com Question: Given an input string s, reverse the ...

  8. leetcode面试准备:Reverse Words in a String

    leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. ...

  9. 345. Reverse Vowels of a String(C++)

    345. Reverse Vowels of a String Write a function that takes a string as input and reverse only the v ...

  10. 【LeetCode练习题】Reverse Words in a String

    Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...

随机推荐

  1. GridView 和DataGrid区别

    转自:http://blog.csdn.net/51357/article/details/1480599 近期在维护一个vs2008开发的项目(该项目是从Vs2013拷贝升级过来的),发现不同时期按 ...

  2. Java虚拟机内存管理原理基础入门

    Jdk:Java程序设计语言.Java虚拟机.Java API类库. Jdk是用于支持Java程序开发的最小环境. Jre:Java API类库中的Java SE API子集.Java虚拟机. Jre ...

  3. android中的万能适配器BaseAdapter的总结

    有时候,列表不光会用来做显示用,我们同样可以在在上面添加按钮.添加按钮首先要写一个有按钮的xml文件,然后自然会想到用上面的方法定义一个适配器,然后将数据映射到布局文件上.但是事实并非这样,因为按钮是 ...

  4. Sql Server之旅——终点站 nolock引发的三级事件的一些思考

    曾今有件事情让我记忆犹新,那年刚来携程不久,马上就被安排写一个接口,供企鹅公司调用他们员工的差旅信息,然后我就三下五除二的给写好 了,上线之后,大概过了一个月...DBA那边报告数据库出现大量锁超时, ...

  5. webconfig 文件加密处理

    前几日正好遇到配置文件加密解密的问题,简单记录下流程. 1.首先运行cmd然后打开Framework.cd C:\Windows\Microsoft.NET\Framework\v4.0.303192 ...

  6. OOP应用:实体类

    实体类 定义:实体类是一个业务实体的类,而业务实体就是整个软件系统业务所涉及的对象. 使用: 1.新增实体类项目,增加类库项目,以.Modes作为后缀. 2.抽取对象以及属性.(简单地说,对象就是每个 ...

  7. [SqlServer]创建链接服务器

    把一个数据库中数据表中的内容,从一个SQL SERVER服务器 导出到另一个SQL Server服务器 不同服务器数据库之间的数据操作 --创建链接服务器  exec sp_addlinkedserv ...

  8. eclipse常用配置

    一. 手动方式安装svn插件 1. 根据本地的svn客户端的版本,到http://subclipse.tigris.org/ 下载eclipse对应版本的svn插件包 注:装eclipse里面的svn ...

  9. 企业邮箱在Android(安卓)系统手机上POP3/IMAP协议的设置方法

    此处以三星(系统版本4.4.2)为例,介绍下使用安卓系统自带的客户端如何设置pop/imap协议方式方法 以下我们将使用test@zhuyuming.so 为测试案例,请您操作时更换成您自己的邮箱账号 ...

  10. shell脚本学习指南

    一.UNIX各个工具所支持的正则表达式: 二.使用sed在某一目录下建立一份目录备份: find /home/foo/ -type d -print | #找出/home/foo/目录下所有目录文件 ...