Drunk Uncle (sorry M.E. and AUS for region lock)
is a fictional character from Saturday Night Live. He often
confuses words for others that sound like them. For this challenge
you need to convert normal speech into drunkspeak.
アルゴリズム
drunkspeakに翻訳するには、テキスト内の単語の順番を入れ替える必要があります。スワップは、2つの単語の酔いしれの類似性に基づいています。酔っぱらいの類似性は、
2つの単語が同じ指標で出現する文字の数として定義されます。しかし、
2つの同一単語の酔いしれ類似度は-1です。例えば、 tree
と
friend
は、ともに ‘r’をインデックス1に、
‘e’をインデックス3に持つため、2の酔いの類似性を持ちます。
あなたがしなければならないのは、最高の酔っぱらいの類似性を持つテキストの2つの単語を見つけて、それらを入れ替えることだけです。
2つの用語を交換すると、もう移動しません。次に、残りのスワップ可能な用語を見て、最高の酔っぱらいの類似性を持つ2つを入れ替えます。あなたはこれ以上スワップできなくなるまでこれを続けます。次に、更新されたテキストを出力するか、関数を返します。
詳細
- For simplicity, input is a list of words consisting of
characters in [A-Za-z] - Every input contains at least one word
- Letter matching is case-insensitive:
A
matches
witha
(Note: Due to this rule
Dog
anddog
are identical, and thus have
a D.S. of -1) - If multiple pairs have the highest drunkenness similarity:
- Of the words, that can maximize drunkenness similarity, pick
the one with the lowest index in the list - Pair that word with the lowest-index word that maximizes
drunkenness similarity
- Of the words, that can maximize drunkenness similarity, pick
例
-
Drunk Uncle needs your help
(title)- S1: Drunk<=>your (DS: 1)
your Uncle
needs Drunk help - S2: needs<=>help (DS: 1)
your Uncle help
Drunk needs - Output:
your Uncle help Drunk needs
- S1: Drunk<=>your (DS: 1)
-
I love fidget spinners
(boring example)- S1: I<=>love (DS: 0)
love I fidget
spinners - S2: fidget<=>spinners (DS: 0)
love I
spinners fidget
- S1: I<=>love (DS: 0)
-
dog eat dog ear
- S1: eat<=>ear (DS: 2)
dog ear dog
eat - S2: dog<=>dog (DS: -1)
dog ear dog
(this step just formality)
eat
- S1: eat<=>ear (DS: 2)
-
Let me tell you a story
- S1: Let<=>me (DS: 1)
me Let tell you a
story - S2: tell<=>you (DS: 0)
me Let you tell a
story - S3: a<=>story (DS: 0)
me Let you tell
story a
- S1: Let<=>me (DS: 1)
-
Too many money and purple people
- S1: purple<=>people (DS: 4)
Too many
money and people purple - S2: many<=>money (DS: 2)
Too money many
and people purple - S3: Too<=>and (DS: 0)
and money many Too
people purple
- S1: purple<=>people (DS: 4)
Let me know if there are more 例 you want me to cover.