字符串去特定字符
题目描述
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
输入
测试数据有多组,每组输入字符串s和字符c。
输出
对于每组输入,输出去除c字符后的结果。
样例输入
goaod
a
#include <stdio.h>
#include <string.h>
int main(){
char c,s[300];
while (gets(s) != NULL)
{
scanf("%c",&c);
int len = strlen(s);
for(int i=0;i<len;i++){
if(s[i] != c){
printf("%c",s[i]);
}
}
printf("\n");
getchar(); /注意:使用 getchar() 将 \n 吸收掉,否则会出错
}
return 0;
}
AC