题目描述:
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
输入:
测试数据有多组,每组输入字符串s和字符c。
输出:
对于每组输入,输出去除c字符后的结果。
样例输入:
heallo
a
样例输出:
hello
来源:
2009年哈尔滨工业大学计算机研究生机试真题
#include<stdio.h>
#include<string.h>
int main(){
char s[1024];
char c;
char p[1024];
while(scanf("%s\n%c", s, &c)!=EOF){
//memset(s, 0, sizeof(s));
//memset(p, 0, sizeof(p));
int l= strlen(s);
s[l]='\0';
int j= 0;
for(int i= 0; i< l; i++){
if(s[i]!= c){
p[j]= s[i];
j++;
}
}
p[j]= '\0';
printf("%s\n", p);
}
return 0;
}