单词翻转
2015-11-15 16:56
190 查看
//将一句话翻转 // I am a student--> student a am I //先每个单词翻转,再整句话翻转 1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 class InvertWords{ 6 public: 7 InvertWords(string* wo):words(wo){} 8 void Invert() 9 { 10 int len=words->size(); 11 int beg=-1; 12 //翻转整个字符串 13 InvertWord(beg,len); 14 //翻转每个单词 15 for(int i=0;i<len;i++) 16 { 17 if(words->at(i)==' ') 18 { 19 InvertWord(beg,i); 20 beg=i; 21 } 22 } 23 } 24 25 private: 26 void InvertWord(int beg,int end) 27 { 28 char tmp; 29 while(++beg<--end) 30 { 31 tmp=words->at(beg); 32 words->at(beg)=words->at(end); 33 words->at(end)=tmp; 34 } 35 } 36 string* words; 37 };
相关文章推荐
- glib 学习
- NOIP2015提高组 总结&反思
- linux进程间的通信机制——信号
- 获取手机基本信息的工具类
- 【程序员技术练级】学习一门脚本语言 python(一)文件处理
- XMC4200的片内FLASH的使用。
- 《将来的你, 一定会那“啥啥啥”》 某某
- sicily 1156. Binary tree
- linux设备驱动之pci设备的驱动架构
- java泛型(一)、泛型的基本介绍和使用
- Day 8(11.15):存储过程(6)--错误处理
- 优先队列的使用
- 友盟移动开发平台.NET版本SDK
- 软件产品和软件项目区别(来自知乎 和华虫网)
- 计算机视觉算法与代码
- ubuntu14.04,安装Git(源代码管理工具)
- ubuntu14.04,安装Git(源代码管理工具)
- ubuntu14.04,安装Git(源代码管理工具)
- 信息安全系统设计基础第九周学习总结
- 11.11评论