创建 2 个字符数组的所有单词变体

发布于 2024-08-29 08:49:24 字数 551 浏览 3 评论 0原文

我有 2 个字符串集合 例如:

List<string> one = new List<string>;
one.Add("a");
one.Add("b");
one.Add("c");

List<string> two = new List<string>;
two.Add("x");
two.Add("y");
two.Add("z");

我想做的是创建一个可以由此创建的所有单词变体的列表。 但我只想创建 4 个字符的单词! 例如,我想要这样的词:“

axax (from one[1],two[1],one[1],two[1])
ayax (from one[1],two[2],one[1],two[1])
azax (from one[1],two[3],one[1],two[1])

最终得到

czcz (from one[3],two[3],one[3],two[3])

任何有关生成此内容的最快和最佳方式的建议”

I have 2 collections of caracter string
ex:

List<string> one = new List<string>;
one.Add("a");
one.Add("b");
one.Add("c");

List<string> two = new List<string>;
two.Add("x");
two.Add("y");
two.Add("z");

What i would like to do is create a list of all the variations of words that can be created from this.
But i only want to create 4 character words!
so for example i would want words like

axax (from one[1],two[1],one[1],two[1])
ayax (from one[1],two[2],one[1],two[1])
azax (from one[1],two[3],one[1],two[1])

eventually getting to

czcz (from one[3],two[3],one[3],two[3])

Any suggestions on the fastest and best way to generate this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我家小可爱 2024-09-05 08:49:24

我怀疑这个解决方案是否会赢得任何速度奖,但它应该相当快:

var one = new [] { "a", "b", "c" };
var two = new [] { "x", "y", "z" };

var ot = from o in one from t in two select o + t;
var r = from f in ot from s in ot select f + s;
var list = r.ToList();

I doubt this solution will win any speed awards, but it should be reasonably quick:

var one = new [] { "a", "b", "c" };
var two = new [] { "x", "y", "z" };

var ot = from o in one from t in two select o + t;
var r = from f in ot from s in ot select f + s;
var list = r.ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文