标题:[求助]求一个程序~~谢谢
只看楼主
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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-146419-1-1.html




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

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