小米麪試題 從一個字符串中刪除在另一個字符串中出現的字符

// ConsoleApplication1.cpp : 定義控制檯應用程序的入口點。
//


#include "stdafx.h"
#include<iostream>
using namespace std;
void fun(char *a , char *b)
{
if(a==NULL||b==NULL)
return;
char *pslow=NULL;
char *pfast=NULL;
int arr[256]={0};
int i=0;
for(i=0;i<256;i++)
arr[i]=0;
char *bpoint=b;
while (*bpoint!='\0')
{
arr[*bpoint]=1;
bpoint++;
}
cout<<1;
pslow=a;
pfast=a;
while (*pfast!='\0')
{
if (arr[*pfast]==1)
{
pfast++;
}else
{
*pslow=*pfast;
pslow++;
pfast++;
}
}
cout<<2;
*pslow='\0';
cout<<a<<endl;


}
int _tmain(int argc, _TCHAR* argv[])
{
char a[]="aabbccdefghijjjjt";
char b[]="adddfj";
fun(a,b);
return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章