- 题目描述:
-
输入字符串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
%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] = ' ';
printf("%s
", stmp);
}
return 0;
}
/**************************************************************
Problem: 1049
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/