周六,刚顾着陪女朋友玩了,九度OJ想AC一道简单的题目,结果在scanf上遇到了点问题,唉,周六大好的时间就没有深入研究,今天趁着来公司看了一下scanf实现机制,解决了
靠,蛋疼的csdn,刚才写了一大堆竟然没保存,直接上代码了
-
题目描述:
-
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。
-
输入:
-
测试数据有多组,每组输入字符串s和字符c。
-
输出:
-
对于每组输入,输出去除c字符后的结果。
-
样例输入:
-
heallo a
-
样例输出:
-
hello
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[1000],ch,a;
int i,len;
while(scanf("%s",str) != EOF)
{
a = getchar(); //吸收scanf最后一个回车字符
scanf("%c",&ch);
len = strlen(str);
for(i = 0; i < len; i++)
{
if(str[i] != ch)
{
printf("%c",str[i]);
}
}
printf("\n");
}
return 0;
}