题解 | #删除公共字符#
删除公共字符
https://www.nowcoder.com/practice/f0db4c36573d459cae44ac90b90c6212
#include <stdio.h>
#include <string.h>
//方法1
int is_exist(char x,char* n)
{
int i = 0;
while (n[i])
{
if (x == n[i])//找到了
{
return 1;
}
i++;
}
return 0;
}
int main() {
char arr1[101] = {0};
char arr2[101] = {0};
gets(arr1);
gets(arr2);
//方法2,调用strchr库函数,在字符串中找是否出现过该字符
int i = 0;
for (i = 0;i < strlen(arr1); i++)
{
if (strchr(arr2, arr1[i]) == NULL)//没找到相同的返回NULL
{
printf("%c",arr1[i]);
}
}
return 0;
}

