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. php鼠标滚动加载

    http://www.thinkphp.cn/extend/772.html 滚动距离js判断 i = 1; //设置当前页数 $(function() { var totalpage = 6; // ...

  2. pentaho cde数据联动,下拉框,文本框,图形

    先看一下效果: 开源bi工具pentaho数据联动,和传统意义上的更改数据不同,pentaho cde 需要一个监听来动态传值. 说一下需要注意的几个地方吧 1.参数是不能在两个图表中直接传递的,必须 ...

  3. Oracle视图分类及各种操作讲解(超级好文)

    目录:一.视图的定义: 二.视图的作用: 三.创建视图: 1.权限 2.语法 3.1  创建简单视图   3.2  创建连接视图  3.2.1 连接视图定义  3.2.2 创建连接视图  3.2.3 ...

  4. 烂泥:mysql帮助命令使用说明

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 在安装.管理和使用mysql过程中,你是不是需要记忆很多的mysql命令.而且对于新手来说,很不多的命令不知道该如何应用,对于老手来说很多命令时间长了忘 ...

  5. shell脚本切割tomcat的日志文件

    鉴于在调试logback和log4j的文件切割一直无法成功,随性用shell写个脚本用来切割tomcat下的日志文件(大家如果有在logback或log4j使用文件切割成功的话,可以留下使用方式,先谢 ...

  6. x01.Excel: 合计件数

    由于 VBA 与 Excel 是耦合的,所以还是先看表: 件数的计算,用 Mod 即可.但考虑到要求码洋.数量等多种需求,就该 VBA 登场了.代码如下: '===================== ...

  7. 单片机温度控制系统DS18B20

    单片机温度控制系统核心 由895X系列单片机来控制来驱动18b20温度传感器模块,通过编写C语言代码,来实现对模块的控制驱动,不断的接收读取18b20传过来的温度信号.将传过来的高低位字节经过个人代码 ...

  8. AngularJS 拦截器

    在需要进行身份验证时,在请求发送给服务器之前或者从服务器返回时对其进行拦截,是比较好的实现手段. 例如,对于身份验证,如果服务器返回401状态码,将用户重定向到登录页面. AngularJS通过拦截器 ...

  9. C# 中 SQLite 使用介绍

    关于SQLite SQLite是一款轻型的嵌入式的遵守ACID的关系型数据库管理系统,诞生已有15个年头了.随着移动互联的发展,现在得到了更广泛的使用. 在使用SQLite之前,我们势必要先了解它一些 ...

  10. 微信公众平台C# SDK:Senparc.Weixin.MP.dll

    https://github.com/Senparc/WeiXinMPSDK [转] http://www.cnblogs.com/szw/archive/2013/01/13/senparc-wei ...