Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4466969
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-05-13 16:22:43

 
/*
python的string是不可变的,故无法进行in-place的反转;因而写一段C++代码作为演示
*/
//可以单独放入一个头文件
#include
using std::reverse;
using std::find;
template
String& reverse_word(String* str){
typename String::iterator i=str->begin(),pre=i,end=str->end();
while(i!=end){
i=find(pre,end,' ');
reverse(pre,i);
pre=i+1;
}
reverse(pre,i);
reverse(str->begin(),str->end());
return *str;
}
//主程序
#include
#include
using namespace std;
int main(){
string c="idea good a have";//idea good a have
do{
cout<}while(getline(cin,c));
return 0;
}
阅读(2046) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~