Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".


题解:用栈就行了

代码:

 class Solution {
public:
void reverseWords(string &s) {
stack<string>st;
string temp = ""; for(int i = ;i <= s.length();i++){
if(i == s.length())
{
st.push(temp);
}
else if(s[i] != ' '){
temp += s[i];
}
else
{
if(temp != ""){
st.push(temp);
temp = "";
}
}
}
s = "";
while(!st.empty()){
if(st.top() != " ")
s += st.top();
st.pop();
if(!st.empty() && s != ""){
s += " ";
}
}
}
};

最新文章

  1. [make]makefile使用积累
  2. 新华龙电子推出最新网络开发板(W5100&amp;W5500方案)
  3. Android Handler机制(三)----Looper源码解析
  4. java中关于try、catch、finally中的细节分析
  5. Day20_IO第二天
  6. 基于Java的数据采集(终结篇)
  7. spring 注解简单使用
  8. sqlserver compact sdf, sqlite 数据库 在net中相对路径设置方法 - 摘自网络
  9. Sublime Text 3配置LiveReload实现实时刷新
  10. poj 1036 Gangsters
  11. Eclipse选项卡式的属性视图(The Eclipse Tabbed Properties View)
  12. 团队作业2:需求分析&amp;原型设计
  13. SAP MM ME29N 试图取消审批报错 - Document has already been outputed(function not possible) -
  14. openstack搭建之-基础服务配置(7)
  15. Mac 端配置 Lua 环境
  16. VC++、Win32 SDK、MFC的区别
  17. java.sql.SQLException: com.mysql.jdbc.Driver
  18. 【php】thinkphp以post方式查询时分页失效的解决方法
  19. LeetCode 34 Search for a Range (有序数组中查找给定数字的起止下标)
  20. BI开发(ETL-DW)

热门文章

  1. (六)Thymeleaf的 th:* 属性之—— th: -&gt;text&amp; utext&amp; href
  2. [腾讯 TMQ] 零基础学习 Fiddler 抓包改包
  3. index+small+row+if经典函数组合应用
  4. Java 下载JDK账号
  5. Git(四):理解和使用分支
  6. Android设计模式(十五)--备忘录模式
  7. 使用strace,lstrace,truss来跟踪程序的运行过程
  8. 图像处理之基础---2个YUV视频 拼接技术
  9. VS使用WEB DEPLOY发布
  10. output的使用