Algorithm question: Remove strings (interesting)
/* Two strings A and B. Remove characters that exist in B from. For example, if A = "hello world" and B = er, then A becomes hllo wold after removal. The space complexity requirement is O (1). The better the time complexity, the better. */# Include
# Include
Using namespace std; void Grial (char * str, char * ptr) {char sP [32]; // use 32 char to represent a two-dimensional table. Memset (sP, '', sizeof (sP); // this field must be cleared. Char * p = ptr; while (* p! = '') {SP [* p> 3] | = (0x1 <(* p & 0x7); p ++; // map the ptr to 32 char-type arrays. If yes, the/position is 1. } P = str; char * q = p; while (* p! = '') // Start to remove. {If (sP [* p> 3] & (0x1 <(* p & 0x7) {p ++;} else {if (q! = P) * q = * p; q ++; p ++; }}* q = '';} int main () {char A [] = hello word; char B [] = er; Grial (A, B); cout <endl; return 0 ;}