C 字符串去特定字符(九度OJ 1049)

来源:互联网 发布:小猪源码下载 编辑:程序博客网 时间:2024/05/22 10:30

题目描述:

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

输入:

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

输出:

对于每组输入,输出去除c字符后的结果。

样例输入:
healloa
样例输出:
hello

源代码:

#include <stdio.h>#include <string.h>int main(){    char str[100000];    char c;    int i,len;    while(gets(str))    {        scanf("%c",&c);        len=strlen(str);        for(i=0;i<len;i++)        {            if(str[i]!=c)                printf("%c",str[i]);        }        printf("\n");        getchar();    }    return 0;}

程序截图:




0 0