"Optimal Solution"
We assume that letters are made up of capital letters ..., we first preprocess small strings,
You can get what characters are contained in B, which can be used in bitwise operations, or in bool arrays. Bit Operation Simplification
Single, use 26bit in an int to indicate whether it appears in B.
BOOL Acontainsb (char *a,char *b) {
int has = 0;
while (*b) {
Have |= 1 << (* (b++)-' A '); Put a.. Z corresponds to 0. 26
}
while (*a) {
if (with & (1 << (* (a++)-' A ')) = = 0) {
return false;
}
}
return true;
}
The idea is summarized as follows:
1. Define a minimum of 26 primes corresponding to the character ' a ' to ' Z ', respectively.
2. Traverse the long string to obtain the product of the corresponding prime number for each character.
3. Traverse the short string to determine whether the product is divisible by the prime number of characters in the short string.
4. Output results.
Where the above procedure is to be improved
1. Only uppercase characters are considered, and if lowercase characters and arrays are considered, the array of prime numbers requires more primes
2. Do not consider duplicate characters, can be added to determine the repetition of the auxiliary array of characters.
Large integer division of Code, followed by publication.
The No. 02 Chapter: Whether the string contains