// 从第一个字符串中删除第二个字符串中出现过的所有字符 #include <stdio.h> char* remove_second_from_first( char *first, char *second ) { if( first == NULL || second == NULL ) { printf("first or/and second should not be NULL\n"); return NULL; } char flag[256]={0}; char *p, *q; p = second; while( *p != ‘\0‘ ) flag[*p++] = 1; p = q = first; while( *q != ‘\0‘ ) { if( flag[*q] == 1 ) { q++; continue; } *p++ = *q++; } *p = ‘\0‘; return first; } int main(void) { char s1[101], s2[101]; scanf("%s",s1); scanf("%s",s2); char *result = remove_second_from_first(s1,s2); printf("%s\n",result); return 0; }
从第一个字符串中删除第二个字符串中出现过的所有字符,布布扣,bubuko.com
时间: 2024-10-11 06:30:37