字符串翻转
来源:互联网 发布:ubuntu 16.04qq下载 编辑:程序博客网 时间:2024/06/14 04:27
原文地址:http://blog.csdn.net/wangyuling1234567890/article/details/39610373
将字符串翻转,如下:
输入:Hi Welcome to cricode
输出:cricode to Welcome Hi
#include <iostream>#include <string>#include <stack>using std::cout;using std::endl;using std::string;using std::stack;void main(){ string str("Hi Welcome to cricode");stack<char> cstack;stack<char> tmp;int index = 0;for (index = 0; index < str.size(); index++){cstack.push(str[index]);}index = 0;while(!cstack.empty()){if (' ' == cstack.top()) // 事例代码,未对标点符号做判断{while(!tmp.empty()){str[index++] = tmp.top();tmp.pop();}str[index++] = ' ';cstack.pop();}else{tmp.push(cstack.top());cstack.pop();}}while(!tmp.empty()){str[index++] = tmp.top();tmp.pop();}cout<<str<<endl;return ;}
0 0
- 翻转字符串
- 翻转字符串
- 字符串翻转
- 字符串翻转
- 翻转字符串
- 翻转字符串
- 字符串翻转
- 翻转字符串
- 翻转字符串
- 字符串翻转
- 翻转字符串
- 字符串翻转
- 翻转字符串
- 字符串翻转
- 翻转字符串
- 字符串翻转
- 字符串翻转
- 字符串翻转
- ASP.NET总结
- MapRecude2.0 c++编程步骤
- 孙红雷携女友珠宝店挑大钻戒 获VIP专属服务
- 程序员 2014-9-27 奇妙之旅
- Unity自定义输入参数说明
- 字符串翻转
- Unix、Linux、Windows的暗黑史
- NYOJ 115 城市平乱
- ReportStudio进阶教程(十) - 图表-基本图表介绍
- LINQ to SQL语句之用户定义函数(存储过程标量函数)
- 机器学习前沿热点--Deep Learning
- 跟我一起学extjs5(28--加入模块和菜单定义[1建立数据库和表])
- 风扇控制系统--初版
- 排序算法总结(三)