单词混杂算法 [英] Word Jumble Algorithm

查看:71
本文介绍了单词混杂算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个单词混乱(即ofbaor),解开字母以创建一个真实单词(即foobar)的方法是什么?我可以看到它有两种方法,我想我知道如何在.NET中进行操作,但是我很好奇看到其他一些解决方案是什么样的(总是很高兴看到我的解决方案是否最佳).

Given a word jumble (i.e. ofbaor), what would be an approach to unscramble the letters to create a real word (i.e. foobar)? I could see this having a couple of approaches, and I think I know how I'd do it in .NET, but I curious to see what some other solutions look like (always happy to see if my solution is optimal or not).

这不是家庭作业或类似的事情,我只是在报纸的本地漫画部分看到一个单词混乱(是的,不错的老式新闻纸),并且我的工程师开始思考.

This isn't homework or anything like that, I just saw a word jumble in the local comics section of the paper (yes, good ol' fashioned newsprint), and the engineer in me started thinking.

如果可以的话,请张贴一些伪代码或真实代码;看到这样的例子,尝试扩展语言知识总是很高兴的.

edit: please post some pseudo code or real code if you can; it's always nice to try and expand language knowledge by seeing examples like this.

推荐答案

有一个字典,该字典由按顺序排列的每个单词的字母键组成.然后带您将字母弄乱-在字典中按该字母排序的字符串查找所有单词.

Have a dictionary that's keyed by the letters of each word in sorted order. Then take you jumble an sort the letters - look up all the words in the dictionary by that sorted-letter string.

因此,例如,单词"bear"和"bare"将在字典中如下所示:

So, as an example, the words 'bear' and 'bare' would be in the dictionary as follows:

key    word
-----  ------
aber    bear
aber    bare

如果给您一个混乱的字母"earb",则可以将字母排序为"aber",并能够在字典中查找两个可能的单词.

And if you're given the jumble, 'earb', you'd sort the letters to 'aber' and be able to look up both possible words in the dictionary.

这篇关于单词混杂算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆