您的位置:首页 > 其它

九度oj 1049

2015-08-11 11:49 225 查看
题目描述:

输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
输入:

测试数据有多组,每组输入字符串s和字符c。
输出:

对于每组输入,输出去除c字符后的结果。
样例输入:
heallo
a

样例输出:
hello

来源:
2009年哈尔滨工业大学计算机研究生机试真题
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[1000];char c[10];
while(gets(str))
{
string s=str;

gets(c);
string b=c;
int t=s.find(b,0);
while(t!=string::npos)
{
s=s.erase(t,b.size());
t=s.find(b,0);
}
t=s.find(' ',0);
while(t!=string::npos)
{
s=s.erase(t,1);
t=s.find(' ',0);
}
cout<<s<<endl;
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: