doomdiablos@yahoo.com
BAN USERThe answer to this depends whether it's intended to be case sensitive or not, are they alpha numeric only or any character, the size of the character (wide or single byte character), ...etc, but basically, this should work for the basic case of exact matching, and if we wanted we can modify it for any change in the requirement...
bool isContained(char* a, char* b) {
if (a == NULL || b == NULL){
return false;
}
int CharMap[sizeof(char) << 8];
ZeroMemory(CharMap, sizeof(CharMap));
for (char *c = &a[0]; c[0] != '\0'; c++) {
CharMap[c[0]-1]++;
}
for (char *c = &b[0]; c[0] != '\0'; c++) {
if (CharMap[c[0]-1] > 0) {
CharMap[c[0]-1]--;
}
}
for (int i = 0; i<_countof(CharMap); i++) {
if (CharMap[i] != 0) {
return false;
}
}
return true;
}
Not correct, 1x1 would contain only one black, the request is to contain "all" black.
- doomdiablos@yahoo.com April 30, 2014