求助:多for循环
各位大虾好!
遇到了一个多for循环:
程序的目的是查找不同的内容:
比如:有下列数据
1 2 3
1 3 5
1 2 6
3 7 8
2 4 5
3 5 6
要找出 n 列这些数据中所有数据都不同的数据列
比如:如果 n=3
那么:
1 2 3
3 7 8
2 4 5
符合要求
结果,我用for 循环遍历整个数据,从第一个开始,找第二个,有相同项,放弃,无相同项,然后再找第三个。这样程序可行,但是找三组用3个for循环,如果找20~30个,就要用20~30个for循环,看别人说递归可以解决,可以做不出来。
请问各位大侠,有没有什么好办法解决,或者递归该怎么做,谢谢了!
for i=0 to row-1
tt=objcus(i).sen
for j=0 to row-1
yy=objcus(j).sen
if yy=tt then
else
for k=0 to row-1
nn=objcus(k).sen
if tt=nn or yy=nn then
else
debug.print("rowindex=" & rowindex)
end if
next
next
next
[最优解释]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[][] data =
{
new int[] { 1, 2, 3 },
new int[] { 1, 3, 5 },
new int[] { 1, 2, 6 },
new int[] { 3, 7, 8 },
new int[] { 2, 4, 5 },
new int[] { 3, 5, 6 }
};
var result = data.GroupBy(x => x[0]).Select(x => x.First())
.GroupBy(x => x[1]).Select(x => x.First())
.GroupBy(x => x[2]).Select(x => x.First());
foreach (var item in result)
{
Console.WriteLine(string.Join(", ", item.ToArray()));
}
}
}
}
1, 2, 3
3, 7, 8
2, 4, 5
Press any key to continue . . .
[其他解释]
怎么会有20-30个循环呀.我玩下这个
[其他解释]
我草,才看懂你的意思,这个交给数据库就好简单了,哈哈,就是返回第一个数字是唯一的结果,并且根据第一个数字,返回后面的两个.
select distinct A.1 from A
然后再把这张表跟它自己合并一次.哈哈...
[其他解释]
有点难度,因为还要考虑接下来的,哈哈,你自己慢慢玩吧,我下班了..
[其他解释]
不好意思,版主。今天才回来,谢谢您的代码,明天我做一下,有问题再请教您!
[其他解释]
先结贴,版主的已经出来了!先谢谢了,有问题再请教您吧!
谢谢大家!
[其他解释]
版主 :
显示 以下 错误:
错误1与“string.Join(string, string[])”最匹配的重载方法具有一些无效参数C:\Documents and Settings\Majinlong\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs3235WindowsFormsApplication1
错误2参数“2”: 无法从“int[]”转换为“string[]”C:\Documents and Settings\Majinlong\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs3253WindowsFormsApplication1