在C#中找到数字的独特梳理。
要查找数字的唯一组合的任务:
输入数据和预期结果:
示例1:(1,2),(3)。结果1:(1,3),(2,3)
示例2:(1,2),(1,2)。结果2:(1),(2),(1,2)
示例3:(1,2),(1,2),(4,5),(3)。结果2:(1,4,3),(1,5,3),(2,4,3),(2,5,3),(1,2,4,3) 5,3)
这是不起作用的示例:
for (var k = 0; k < maxLength; k++)
{
var resultSet = new SortedSet<int>();
for (var i = 0; i < packs.Count; i++)
{
var currentSet = packs[i];
var currentElement = currentSet.ElementAt(k);
resultSet.Add(currentElement);
for (var s = i + 1; s < packs.Count; i++)
{
var setToTakeElement = packs[s];
for (var j = 0; j < maxLength; j++)
{
var element = currentSet.ElementAt(j);
resultSet.Add(element);
}
}
}
}
有什么想法解决它?
There is the following task to find unique combination of numbers:
Input data and expected result:
Example 1: (1, 2), (3). Result 1: (1, 3), (2, 3)
Example 2: (1, 2), (1, 2). Result 2: (1), (2), (1, 2)
Example 3: (1, 2), (1, 2), (4, 5), (3). Result 2: (1, 4, 3), (1, 5, 3), (2, 4, 3), (2, 5, 3), (1, 2, 4, 3), (1, 2, 5, 3)
Here is the example that didn't work:
for (var k = 0; k < maxLength; k++)
{
var resultSet = new SortedSet<int>();
for (var i = 0; i < packs.Count; i++)
{
var currentSet = packs[i];
var currentElement = currentSet.ElementAt(k);
resultSet.Add(currentElement);
for (var s = i + 1; s < packs.Count; i++)
{
var setToTakeElement = packs[s];
for (var j = 0; j < maxLength; j++)
{
var element = currentSet.ElementAt(j);
resultSet.Add(element);
}
}
}
}
Any ideas how to solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论