comparison of permutations

Hi, the task I am given is to compare words that the user types in with the censored words. Each word that is not allowed (at least one permutation matches a censored word) needs to have its first and last letter replaced with a '*'. So if "cobra" is a censored word, "arbok" has to output "*rbo*".
Please help!
(at least one permutation matches a censored word)
You only need to compare characters, if you sort the words it would be simpler
how is "cobra" an permutation of "arbok"?
I see a problem here. Say "noob" was a censored word. If anyone were to say "boon" (which is a word with a completely different meaning), it'd be censored. There's a more likely example with the word "hits". But! That aside...

I'd go along with ne555's suggestion of taking each word (as an std::string), sorting it, and comparing that with each of the censored words, which would also be sorted. It's a simple way of checking what characters are in a string regardless of their order. :)

@blueberry
I think the OP meant "arboc". Just a guess. >_>

-Albatross
Last edited on
Right, sorting the words out will make it much simpler, thanks a bunch both!

My sincerest apologies for the arbok mistake, and I would go with "kobra" :P
Topic archived. No new replies allowed.