If the characters of the two string are the same, but the order is different, it is considered a brothers strings. For example, BAD and ADB are brothers string, which now provides a string, how to quickly find its brother string in the dictionary in the dictionary ,,
Please describe the data structure and query process.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*Test the string
*/
char * substring (char * src, int pos, int len) {
char *p = src;
char *substr = calloc (sizeof (char), len + 1);
int i = 0;
p += pOS;
While (len-) {
substr [i ++] = *(p ++);
}
substr [i] = '\ 0';
Return substr;
}
int Gethash (char *p) {
int Hash = 0;
int length = strlen (p);
int i = 0;
for (; I <langth; i ++) {
have | = (1 << (p [i] -'a'));
}
Return have;
}
Void Sibilingstring (Char* Dict, Char* Target) {
int size = strlen (dict);
int Start = 0;
int Len = Strlen (target);
int END = Len -1;
int targethash = gethash (target);
While (END ++ <SIZE) {
char *substr = substring (Dict, Start ++, Len);
/*If you want to be consistent with the brothers' string* /
ifThash (Substr) == Targethash) {
puts (substr);
}
}
}
int Main (void) {
char *src = "worldhello";
puts ("Sibiling Strings:");
sibilingstring (src, "heoll");
Return exit_success;
}