using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{ List<int> list1 = new List<int> { , , };
List<int> list2 = new List<int> { , , };
List<int> list3 = new List<int> { , , }; List<int> list4 = new List<int> { , , };
List<int> list5 = new List<int> { , , }; List<int> list6 = new List<int> { , , };
List<int> list7 = new List<int> { , , }; List<List<int>> list = new List<List<int>>();
list.Add(list1);
list.Add(list2);
list.Add(list3);
list.Add(list4);
list.Add(list5);
list.Add(list6);
list.Add(list7); List<int> allint = new List<int>();//所有的集合数据
HashSet<int> repeated = new HashSet<int>(); //得到没有重复的hashset
foreach (List<int> item in list)
{
foreach (int index in item)
{
if (allint.Contains(index))
repeated.Add(index);//得到所有重复的集合的元素
allint.Add(index);//得到所有的集合的元素
}
} foreach (var setkey in repeated)//循环重复的值
{
List<int> templist = null;//临时
List<List<int>> removelist = new List<List<int>>();
foreach (var item in list)//循环
{
//if (templist == null)
//{
// templist = item;
// removelist.Add(item);
//} //if (item.Contains(setkey))
//{
// removelist.Add(item);
// templist = templist.Union(item).ToList();
//} if (item.Contains(setkey))
{
if (templist == null)
{
templist = item;
removelist.Add(item);
}
else
{
removelist.Add(item);
templist = templist.Union(item).ToList();
}
}
}
foreach (var item in removelist)
{
list.Remove(item);
}
removelist.Clear();
list.Add(templist);
} foreach (var item in list)
{
foreach (var item1 in item)
{
Console.Write(item1 + " , ");
}
Console.Write("\r\n");
}
Console.ReadKey();
} }
}

C# 合并只要有交集的所有集合的更多相关文章

  1. delphi将两个Strlist合并,求交集 (保留相同的)

    Function StrList_Join(StrListA,StrListB:String):String; //将两个Strlist合并,求交集 (保留相同的) var SListA,SListB ...

  2. Oracle 取两个表中数据的交集并集差异集合

    Oracle 取两个表中数据的交集 关键字: Oracle 取两个表中数据的交集 INTERSECT Oracle 作为一个大型的关系数据库,日常应用中往往需要提取两个表的交集数据 例如现有如下表,要 ...

  3. 数据规整化:pandas 求合并数据集(交集并集等)

    数据集的合并或连接运算是通过一个或多个键将行链接起来的.这些运算是关系型数据库的核心.pandas的merge函数是对数据应用这些算法的这样切入点. 默认是交集, inner连接 列名不同可以分别指定 ...

  4. List集合中的交集 并集和差集

    目录 List集合求交集 并集 差集 Set集合 Lambda表达式 List集合求交集 并集 差集 两种方法求集 Set集合 交集 两个集合中有相同的元素 抽取出来的数据就是为交集 @Test pu ...

  5. Linq连接查询之左连接、右连接、内连接、全连接、交叉连接、Union合并、Concat连接、Intersect相交、Except与非查询

    内连接查询 内连接与SqL中inner join一样,即找出两个序列的交集 Model1Container model = new Model1Container(); //内连接 var query ...

  6. 14.python中的集合

    什么是集合?正如其字面的意思,一堆东西集中合并到一起.乍一听貌似和容器没什么差别,嗯,好吧,集合也算是一种容器. 在学习这个容器有什么不同之前,先看看集合是如何创建的: a = set() #可变集合 ...

  7. Python学习笔记四--字典与集合

    字典是Python中唯一的映射类型.所谓映射即指该数据类型包含哈希值(key)和与之对应的值(value)的序列.字典是可变类型.字典中的数据是无序排列的. 4.1.1字典的创建及赋值 dict1={ ...

  8. (python)数据结构---集合

    一.描述 set翻译为集合 set是可变的.无序的.不可重复的 set的元素要求可哈西(不可变的数据类型可哈西,可变的数据类型不可哈希) set是无序的,因此不可以索引,也不可以修改 线型结构的查询时 ...

  9. pythonj基础(五)元组和集合

    一,什么是元祖 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 1.创建一个空元组 tu ...

随机推荐

  1. Spring Data JPA入门

    1. Spring Data JPA是什么 它是Spring基于ORM框架.JPA规范封装的一套JPA应用框架,可使开发者用极简的代码即可实现对数据的访问和操作.它提供了包括增删改查等在内的常用功能, ...

  2. 命令行编译C程序

    1 准备工作 下载mingw-get-setup.exe并且安装  参考 http://www.jb51.net/softjc/159871.html 环境变量更新: PATH .;C:\MinGW\ ...

  3. 使用控制台对Redis执行增删改查命令

    使用控制台对Redis执行增删改查命令 在上一篇里,我们已经安装了redis.这一篇我们将一起来学习如何使用"控制台"管理Redis 首先肯定是打开一个控制台,在windows系统 ...

  4. oracle12 group by 拼接字符串

    select listagg(合并字段,'连接符号') within group (order by 排序字段) as 别名 from 表 group by 字段

  5. 项目导入之后报错:The import javax.servlet cannot be resolved

    项目导入之后报错:The import javax.servlet cannot be resolved 解决方法:在Eclipse中,右击项目,选择Build Path->configure ...

  6. 元素定位(d4-2)

    一,元素定位①优先级:首先选择id,其次选class,再就是根据其他唯一元素,在更加层级过滤定位,根据多属性定位,②首选CSS定位,在选XPATH定位 1.xpath定位 //*   获取当前网页全部 ...

  7. vscode插件安装失败的解决方案

    在vscode中点击对应插件的install按钮安装,安装失败,软件提示手动安装(manually install). 手动下载vsix安装包,然后点击install from VSIX...,选择v ...

  8. C++接口与实现的抽象分离

    IPerson.h #ifndef I_PERSON_H_ #define I_PERSON_H_ #include <string> #include <ostream> c ...

  9. MyOD-Linux od命令的实现

    MyOD 一.设计思路 确定MyOD的要求 根据需求可知MyOD需要实现类似Linux下 od -tx -tc XXX的功能,于是先去网上查找了一下od命令的-tx以及-tc参数的作用,经查找后了解到 ...

  10. python-装饰器实现pv-uv

    python-装饰器实现pv-uv   网站流量统计可以帮助我们分析网站的访问和广告来访等数据,里面包含很多数据的,比如访问试用的系统,浏览器,ip归属地,访问时间,搜索引擎来源,广告效果等.原来是一 ...