数组中元素的排列 [英] permutation of array items

查看:138
本文介绍了数组中元素的排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何去获得数2的字符串数组的组合? IE浏览器。

How do I go about getting a combination of an array of strings of count 2? Ie.

List<string> myString = {"a", "b", "c", "d", "f"};

一个排列是这样的:

AB AC 广告 自动对焦 巴 公元前 BD BF CA CB 光盘 CF 等等...

ab ac ad af ba bc bd bf ca cb cd cf etc...

我不知道如何开始这个算法。如果有帮助,我宁愿做一个循环比递归,因为在我的实际执行情况,我必须分配一个值置换项目和比较每一个到另一个选择是最高的。

I have no idea how to begin this algorithm. If it helps, I'd rather do a loop than a recursion because in my actual implementation, I have to assign a value to the permuted items and compare each one to another and select the highest.

推荐答案

使用LINQ:

var result = 
    from a in myString
    from b in myString
    where a != b
    select a + b;

这篇关于数组中元素的排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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