您的位置:首页 > 其它

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

2014-03-18 14:14 218 查看
题目描述:

输入字符串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
****************************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: