1. 请实现一个功能:敏感字符过滤; 输入2个含有很多字符的字符串A和B,如果A中有字符在B中出现,则从A中删除该字符,求剩余字符;比如:输入”12aBc12456ab”,”1abef”,输出”2Bc2456”
#include <iostream>
#include <string>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define MAX_LEN 1024
/*
* ²éÕÒ×Ö·û´®str1ÖÐÓë×Ö·û´®str2ÖÐÓÐÖظ´µÄ×Ö·û
*/
void test1(char* str1, const char* str2)
{
if(NULL == str1 || NULL == str2)
return;
if(strlen(str2) == 0)
return;
char *tmp = str1;
for(;(*str1) != '\0';str1++)
{
const char* tt = str2;
for(tt;*tt != '\0'; tt++)
{
if(*str1 == *tt)
break;
}
if(*tt == '\0')
*(tmp++) = *str1;
}
*tmp = '\0';
return;
}
/*
* mainº¯ÊýÈë¿Ú£¬»ñÈ¡×Ö·û´®
*/
int main(int argc, char *argv[])
{
try
{
char buffer1[MAX_LEN],buffer2[MAX_LEN];
loop:
cout<<"Please input str1 : ";
cin.getline(buffer1,MAX_LEN);
if(0 == strlen(buffer1))
{
cout<<"Please input a string again!"<<endl;
goto loop;
}
cout<<"Please input str2 : ";
cin.getline(buffer2,MAX_LEN);
test1(buffer1,buffer2);
cout<<"[test1]'s result is : "<<buffer1<<endl;
}
catch(...)
{
cout<<"[test1] has a error!"<<endl;
}
return 0;
}