First of all, this is not homework! :)
Say I have an NSString: "the?or?"
For each wildcard i want the string to come back with at least 26 (not including 'ñ' and 'ng' that seem to have been added by some countries like the Phillipines). So a word with 2 ?
would give me 26^2 (i think) results.
I want it to return an NSArray 开发者_JAVA百科of the following:
theaora
theaorb
theaorc
...
thezora
thezorb
thezorc
...
thezorx
thezory
thezorz
Since this is recursion (I am assuming) I am having issues...
I am working on this:
NSArray *countOfWildCardArray = [wordToSearch componentsSeparatedByString:@"?"];
int countOfWildCard = [countOfWildCardArray count] - 1;
if (countOfWildCard > 0)
{
for ( NSInteger i = 0; i < countOfWildCard; i++)
{
NSLog(@"Looking for wildcard #%i",i);
for(char a = 'a'; a <= 'z'; a++)
{
NSString *tempStringA = [NSString stringWithString:wordToSearchFor];
......
}
}
}
and then I am lost. I actually don't think I am on the right track. Like I said, recursion bothers me a lot :)
Does anyone have an idea of what do do?
So, after having received a few questions I will just state that this issue has to do with letting the user know how many anagrams I can make from those resulting words. I have a fast way of making the anagrams for the word list and am simply looking to create the word list that the anagrams are to be made from. I am sure there is a better way than the above method. What I am asking for is some help finding the best way of creating the array.
Try this,
NSArray *wildCardArray;
NSArray *countOfWildCardArray = [wordToSearch componentsSeparatedByString:@"?"];
int countOfWildCard = [countOfWildCardArray count] - 1;
if (countOfWildCard > 0)
{
for(char a = 'a'; a <= 'z'; a++)
{
for(char b = 'a'; b <= 'z'; b++)
{
NSString *tempStringA=[NSString stringWithFormat:@"%@%c%@%c",[countOfWildCardArray objectAtIndex:0],a,[countOfWildCardArray objectAtIndex:1],b];
[wildCardArray addObject:tempStringA];
}
}
}
精彩评论