各位大虾好!遇到了一个多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循环,看别人说递归可以解决,可以做不出来。请问各位大侠,有没有什么好办法解决,或者递归该怎么做,谢谢了!(我是用VB.net做的,各位随意)
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
程序的目的是查找不同的内容:比如:有下列数据
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循环,看别人说递归可以解决,可以做不出来。请问各位大侠,有没有什么好办法解决,或者递归该怎么做,谢谢了!(我是用VB.net做的,各位随意)
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
解决方案 »
- 问一下,有做过音乐网站的吗?
- 求助,字体问题!急!!!!
- 什么是申请内存 释放内存 这时cpu都作了什么??
- 请问C#的容器的特征是什么,适用范围又是什么?
- 新手咨询数组问题??
- 散分了,C#中用什么可以实现像QQ那样传送文件
- vs2003如何C#链接sql server 2008?
- 为什么无法ref string 转换为 ref object
- 在SQL语言“String strSQLcheck="select 模块名称 from 产品模块 where 产品ID=i";”中为什么说找不到i列
- 怎么样才能和大华条码秤的数据同步
- 请教,datagridview如何做出如下效果
- C#调用C++的Dll如何传递CList
private void button1_Click(object sender, EventArgs e)
{
int count = 0;
textBox1.Text = "";
for (int j = 0; j < table.Rows.Count; j++)
{
List<string> strlist = new List<string>();
strlist.Add(table.Rows[j][0].ToString());
strlist.Add(table.Rows[j][1].ToString());
strlist.Add(table.Rows[j][2].ToString());
int str_coun = strlist.Count;
if (str_coun == strlist.Distinct().Count<string>())
{
textBox1.Text += table.Rows[j][0].ToString() + "-" + table.Rows[j][1].ToString() + "-" + table.Rows[j][2].ToString() + "\r\n";
count++;
}
if (count == int.Parse(textBox2.Text))
{
return;
}
}
}
textBox1是输出结果
textBox2相当于你的 n我可以手动输入
int colCount=3,rowCount=8;
int[,] datas = new int[colCount,rowCount];
//....datas初始化略
List<int[]> list = new List<int[]>();
bool find = false;
for (int i = 1; i < rowCount; i++)
{
find = false;
foreach (int[] addrow in list)
{
for (int index = 0; i < colCount; i++)
{
if (addrow[index] == datas[i, index])
{
find = true;
break;
}
}
if (find)
break;
}
if (!find)
{
int[] row = new int[colCount];
for (int k = 0; k < colCount; k++)
{
row[k] = datas[i, k];
}
list.Add(row);
}
}
lyble
先谢谢了!
看得不是很懂,调试的时候出现在
row[k]=datas[i,k]
索引超出了数组界限不好意思,能在关键地方注释两句吗!我看的不是很懂!
for (int i = 1; i < rowCount; i++) 改成
for (int i = 0; i < rowCount; i++) 试试