问题 E: 字符串去特定字符
时间限制: 1 Sec 内存限制: 32 MB
提交: 976 解决: 273
[提交][状态][讨论版][命题人:外部导入]
题目描述
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
输入
测试数据有多组,每组输入字符串s和字符c。
输出
对于每组输入,输出去除c字符后的结果。
样例输入
goaod a
样例输出
good
#include<cstdio>
#include<cstring>
const int maxn = 1010;
int main()
{
char str[maxn]; //行表示单词数量 列表示每一个单词的长度
char str1[110],str2[110];
while(gets(str)!=NULL)
{
int i=0,j=0;
char temp[maxn],c;
scanf("%c",&c);
while(str[i]!='\0')
{
if(str[i]!=c)
temp[j++]=str[i++];
else
i++;
}
temp[j]='\0';
printf("%s\n",temp);
getchar(); //必须加在这里,不能紧跟在scanf后面
}
return 0;
}