Algorithm question: Remove strings (interesting) and remove strings
/* Two strings A and B. Remove characters that exist in B from. For example, if A = "hello world" and B = "er" are removed, then A becomes "hllo wold ". The space complexity requirement is O (1). The better the time complexity, the better. */# Include <iostream> # include <string. h> using namespace std; void Grial (char * str, char * ptr) {char sP [32]; // use 32 char to represent the orders table. Memset (sP, '\ 0', sizeof (sP); // this field must be cleared. Char * p = ptr; while (* p! = '\ 0') {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! = '\ 0') // start to remove. {If (sP [* p> 3] & (0x1 <(* p & 0x7) {p ++;} else {if (q! = P) * q = * p; q ++; p ++; }}* q = '\ 0';} int main () {char A [] = "hello word"; char B [] = "er"; Grial (A, B); cout <A <endl; return 0 ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.