| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:[求助]求一个程序~~谢谢
只看楼主 加入收藏
kikyojlb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-10
收藏
 问题点数:0 回复次数:2 
[求助]求一个程序~~谢谢

例如:
Welcome to China!

反过来输出:
China to Welcome!

要求:必须处理字符串在初始的储存string里

下面是例子
For example:

{

string a;

getline(cin,a); //if you input the string”Welcome to China!”

//your process

//………

cout<<a; //then the output is “China to Welcome!”

}

[此贴子已经被作者于2007-6-10 21:21:20编辑过]

搜索更多相关主题的帖子: Welcome 字符串 China 
2007-06-10 21:19
游乐园
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:671
专家分:0
注 册:2006-11-1
收藏
得分:0 

For example:

{


string a;
getline(cin, a); //if you input the string”Welcome to China!”

//your process
string::size_type pos = a.size()-1, pre_pos = pos;
int size =a.size();

while (pos=a.rfind(' ', pos))
{
a.append(a,pos, pre_pos);
pre_pos=--pos;
}
pos = a.find(' ', 0);
a.append(a, 0, pos-1);
a.erase(a.begin(), a.begin()+size+1);

cout<<a;//then the output is “China to Welcome!”

}


unicorn-h.spaces. ◇◆ sava-scratch.spaces.
2007-06-11 17:33
kikyojlb
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-10
收藏
得分:0 

谢谢~~~~

2007-06-12 10:27
快速回复:[求助]求一个程序~~谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011572 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved