九度OJ 1049:字符串去特定字符 (基础题)
- 题目描述:
 - 
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
 
- 输入:
 - 
测试数据有多组,每组输入字符串s和字符c。
 
- 输出:
 - 
对于每组输入,输出去除c字符后的结果。
 
- 样例输入:
 - 
heallo a
 
- 样例输出:
 - 
hello
 
思路:
这个题其实只要不输出字符c就行啦。
代码:
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char s[40], stmp[40];
    char c;
    int count;
 
    while (scanf("%s\n%c",s, &c) != EOF)
    {
        count = 0;
        for (int i=0; i<strlen(s); i++)
        {
            if (s[i] != c)
            {
                stmp[count] = s[i];
                count++;
            }
        }
        stmp[count] = '\0';
        printf("%s\n", stmp);
    }
 
    return 0;
}
/**************************************************************
    Problem: 1049
    User: liangrx06
    Language: C
    Result: Accepted
    Time:0 ms
    Memory:912 kb
****************************************************************/
    编程算法爱好者。
                    
                
                
            
        
浙公网安备 33010602011771号