#include <cstdio>
#include <cstring>
#include <string>
int main()
{
char str[150],ch;
while(gets(str)!=NULL)
{
//printf("str=%s\n",str);
scanf(" %c",&ch);
//printf("ch=%c\n",ch);
for(int i=0;str[i]!='\0';i++)
{
if(str[i]==ch) continue;
printf("%c",str[i]);
}
printf("\n");
memset(str,0,sizeof(str));
getchar();//不写会出错
}
return 0;
}
这是一个非常水的题,主要想讲一下gets:
读取的换行符会被转化成'\0',来结束字符串的读入。
但是gets之后,再次读取一个字符,不会读到'\n',第二次运行gets却会直接读到'\n',想不通啊!
Description
从键盘输入任意一个字符串和一个字符,要求从该字符串中删除所有该字符。
Input
输入有多组测试数据。
每组两行,第一行是字符串(字符串至少还有一个字符,不多于100个),第二行是一个字符
Output
每组输出一行,删除了所有应删除字符后的字符串
Sample Input
ABCDE
E
ASD Dfg fhd
D
Sample Output
ABCD
AS fg fhd