題目1049:字符串去特定字符

轉運四方海淘網 : zysfht.com

題目描述:

輸入字符串s和字符c,要求去掉s中所有的c字符,並輸出結果。

輸入:

測試數據有多組,每組輸入字符串s和字符c。

輸出:

對於每組輸入,輸出去除c字符後的結果。

樣例輸入:
heallo
a
樣例輸出:
hello
來源:

2009年哈爾濱工業大學計算機研究生機試真題


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main()
{
    char *s=(char *)malloc(sizeof(char));
    char c;
    int len,i;
    while(scanf("%s",s)!=EOF)
    {
        scanf("%c",&c);
        c=getchar();
        len=strlen(s);
        for(i=0;i<len;i++)
        {
            if(s[i]!=c)
                printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
 
 
}
 
/**************************************************************
    Problem: 1049
    Language: C
    Result: Accepted
    Time:0 ms
    Memory:912 kb
****************************************************************/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章