1161: 零起点学算法68——删除字符
Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 2382 Accepted: 850
[Submit][Status][Web Board]
Description
从键盘输入任意一个字符串和一个字符,要求从该字符串中删除所有该字符。
Input
输入有多组测试数据。
每组两行,第一行是字符串(字符串至少还有一个字符,不多于100个),第二行是一个字符
Output
每组输出一行,删除了所有应删除字符后的字符串
Sample Input
ABCDE
E
ASD Dfg fhd
D
Sample Output
ABCD
AS fg fhd
参考代码
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 5 int main() 6 { 7 char str[100],del; 8 while(gets(str)!= NULL) 9 { 10 scanf("%c",&del); 11 getchar(); //这一行特别重要,获取了上一行输入中的‘\n’符号读入 12 int j=0; 13 for(int i=0;str[i]!='\0';i++) 14 { 15 if(str[i]!=del) 16 { 17 printf("%c",str[i]); 18 } 19 } 20 printf("\n"); 21 } 22 return 0; 23 }