1、题目描述

2、题目描述

利用栈实现逆序。

3、代码

 string reverseOnlyLetters(string S) {
if (S.size() == || S.size() == )
return S; stack<string> st;
for (string::iterator it = S.begin(); it != S.end(); it++) {
if ( isalpha(*it) ){
string sub = S.substr(it-S.begin(), );
st.push(sub);
}
} string res; for (auto it = S.begin(); it != S.end(); it++) {
if (isalpha(*it)) {
string sub = st.top();
st.pop();
res += sub;
} else {
string sub = S.substr(it - S.begin(),);
res += sub;
}
} return res;
}

最新文章

  1. getElementsByClassName简单实现
  2. 如何运行python
  3. 43.Android之ListView中BaseAdapter学习
  4. Programs vs. processes
  5. virtual box硬盘扩容 不是加一块硬盘
  6. Java可变长参数方法调用问题
  7. kali linux 一些工具及命令集1(搜集DNS信息)
  8. C++中delete和delete[]的使用
  9. js中常用的Math方法总结
  10. Web应用中监听者的通知顺序按照DD中的定义顺序
  11. 51nod_1605:棋盘问题
  12. Python--Linux上安装Python
  13. 利用div绘制细线居中
  14. Spring Security(二十四):6.6 The Authentication Manager and the Namespace
  15. 关于jquery中on绑定click事件在苹果手机失效的问题
  16. :after伪类+content经典应用举例
  17. redis主从集群搭建及容灾部署(哨兵sentinel)
  18. 【LOJ】#2041. 「SHOI2015」聚变反应炉
  19. μCOS-II系统之事件(event)的使用规则及Semaphore实例
  20. windows下使用Git

热门文章

  1. storm_常用命令
  2. Mysql压缩包版的安装方法详解
  3. 07 - JavaSE之容器
  4. PHP MYSQL登陆和模糊查询
  5. Java队列——线程池创建的例子
  6. [Python学习笔记-003] 使用PyOTP获取基于OTOP算法的动态口令
  7. 微信小程序——豆瓣电影——(2):小程序运行部署
  8. (转)mybatis-plus入门
  9. js实现时间日期的格式化
  10. Quartz2D指定显示范围