Reverse Words in a String
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的更多相关文章
- [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 ...
- [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 ...
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [LintCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- LeetCode Reverse Words in a String II
原题链接在这里:https://leetcode.com/problems/reverse-words-in-a-string-ii/ 题目: Given an input string, rever ...
- 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 ...
- leetcode6 Reverse Words in a String 单词取反
Reverse Words in a String 单词取反 whowhoha@outlook.com Question: Given an input string s, reverse the ...
- leetcode面试准备:Reverse Words in a String
leetcode面试准备:Reverse Words in a String 1 题目 Given an input string, reverse the string word by word. ...
- 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 ...
- 【LeetCode练习题】Reverse Words in a String
Reverse Words in a String Given an input string, reverse the string word by word. For example,Given ...
随机推荐
- 一秒钟看懂SaaS、CRM、OA、ERP、HR、进销存
自2014年以来,SaaS.CRM.OA.ERP.HR.APM.进销存.财务系统等,这些名词大量出现在微信朋友圈.电视楼宇广告和千百万融资资讯中.它们到底是什么意思?相互之间又有什么区别?在这个飞速发 ...
- 用了星型转换的sql跑了5小时--->5mins的过程
=================START================================ BI数据仓库环境里面跑着一个crontab job,一旦sql运行超过4hours,就会接 ...
- easyui datagrid 键盘上下控制选中行
扩展datagrid的一个方法keyCtr $.extend($.fn.datagrid.methods, { keyCtr : function (jq) { return jq.each(fun ...
- Javascript刷新页面的几种方法
Javascript刷新页面的几种方法: window.navigate(location)location.reload()location=locationlocation.assign(loca ...
- C#邮件发送问题(一)
邮件发送需考虑很多因素,包括发送邮件客户端(一般编码实现),发送和接收邮件服务器设置等.如果使用第三方邮件服务器作为发送服务器,就需要考虑该服务器的发送限制,(如发送邮件时间间隔,单位时间内发送邮件数 ...
- 烂泥:更换ESXI5.0管理网卡及管理IP地址
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 公司的服务器基本上都是在IDC机房里面的,为了更有效的利用服务器性能.所以有几台服务器,安装的是ESXI5.0做成虚拟化. 注意目前这些服务器都是双网卡 ...
- my_strstr()
const char* my_strstr(const char* S1,const char* S2){ int i=0,flag=0; while('\0'!=*(S1+i)){ if(*(S1+ ...
- Java enum的用法详解
(转自:http://www.cnblogs.com/happyPawpaw/archive/2013/04/09/3009553.html) 用法一:常量 在JDK1.5 之前,我们定义常量都是: ...
- android MotionEvent 获取长按压时间长
思路: 1.记录ACTION_DOWN的aX, aY坐标: 2.在ACTION_MOVE判断是否移动,移动则取消记录时间,没移动就记录: 3.记录时间,按下坐标,移动坐标分别显示在TextView a ...
- windows下制作linux U盘启动盘或者安装优盘(转)
windows下制作linux U盘启动盘或者安装优盘(转) Linux发行版排行榜:http://iso.linuxquestions.org/ [方案一]:UltraISO(不推荐,在Window ...