求助:多for循环

jinlongma 2012-11-05 03:47:27
各位大虾好!

遇到了一个多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

...全文
135 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinlongma 2012-11-06
  • 打赏
  • 举报
回复
版主 : 显示 以下 错误: 错误 1 与“string.Join(string, string[])”最匹配的重载方法具有一些无效参数 C:\Documents and Settings\Majinlong\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs 32 35 WindowsFormsApplication1 错误 2 参数“2”: 无法从“int[]”转换为“string[]” C:\Documents and Settings\Majinlong\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs 32 53 WindowsFormsApplication1
jinlongma 2012-11-06
  • 打赏
  • 举报
回复
先结贴,版主的已经出来了!先谢谢了,有问题再请教您吧! 谢谢大家!
jinlongma 2012-11-06
  • 打赏
  • 举报
回复
引用 4 楼 caozhy 的回复:
C/C++ code123456789101112131415161718192021222324252627282930using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ConsoleApplication1{ class Pro……
不好意思,版主。今天才回来,谢谢您的代码,明天我做一下,有问题再请教您!
threenewbee 2012-11-05
  • 打赏
  • 举报
回复
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 . . .
lvlvlvlylyly 2012-11-05
  • 打赏
  • 举报
回复
有点难度,因为还要考虑接下来的,哈哈,你自己慢慢玩吧,我下班了..
lvlvlvlylyly 2012-11-05
  • 打赏
  • 举报
回复
我草,才看懂你的意思,这个交给数据库就好简单了,哈哈,就是返回第一个数字是唯一的结果,并且根据第一个数字,返回后面的两个.
select distinct A.1 from A
然后再把这张表跟它自己合并一次.哈哈...

lvlvlvlylyly 2012-11-05
  • 打赏
  • 举报
回复
怎么会有20-30个循环呀.我玩下这个

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧