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. ADO.Net(五)——实战:对战游戏

    对战游戏 要求: 自建数据表(例如:数据表包含:代号,姓名,性别,血量,攻击力,防御力,命中,闪避,等级等字段) 需要通过程序向数据表添加人员 添加的时候,根据用户输入的名字,自动计算生成相应的血量. ...

  2. [20130704] Intra-Query Parallel Thread Deadlocks

    今天碰到了  Intra-Query Parallel Thread Deadlocks 简单的说就是并发查询把自己给锁住了. 原理: 在并发查询运行是,有一个生产者和一个消费者,生产者等待消费者产生 ...

  3. JavaScript Lib Interface (JavaScript系统定义的接口一览表)

    function Object(){}; Object.prototype.toString = function(){return "";}; Object.prototype. ...

  4. mysql技巧之select count的比较

        在工作过程中,时不时会有开发咨询几种select count()的区别,我总会告诉他们使用select count(*) 就好.下文我会展示几种sql的执行计划来说明为啥是这样.   1.测试 ...

  5. SQL Server调优系列玩转篇二(如何利用汇聚联合提示(Hint)引导语句运行)

    前言 上一篇我们分析了查询Hint的用法,作为调优系列的最后一个玩转模块的第一篇.有兴趣的可以点击查看:SQL Server调优系列玩转篇(如何利用查询提示(Hint)引导语句运行) 本篇继续玩转模块 ...

  6. Java api 入门教程 之 JAVA的String 类

    1.String对象的初始化 由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下: String s = “abc”; s = “Java语 ...

  7. windows开关机时间记录

    1. 开机时间记录批处理文件,kai.bat @echo off echo %date% %time% 开机 >>D:\开关机记录\开关机时间.txt 2. 关机时间记录批处理文件,gua ...

  8. 禁止用户选定文本: user-select

    双击文本 select,会被选定,如下 但有时点击元素时不想要被选定的状态,有一个尚未成为标准的 CSS 属性: user-select,它有 4 个值: text 可以选择文本 element 可以 ...

  9. .NET对象的内存布局

    每个虚拟机都有它自己的对象布局,本文我们将针对sscli源码和windbg调试器来查看不同类型的.net对象布局. 在.net虚拟机里,每个对象都需要保存这些信息: 对象的类型: 对象实例的成员属性( ...

  10. [Top-Down Approach] Chatper 4 Notes

    4.2 Virtual Circuit and Datagram Networks VC Set up connection Exchange data Free the connection The ...