单词混杂算法

编程入门 行业动态 更新时间:2024-10-13 10:27:01
本文介绍了单词混杂算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

给出一个单词混乱(即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.

更多推荐

单词混杂算法

本文发布于:2023-11-29 21:18:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   单词

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!