C# 合并只要有交集的所有集合
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# 合并只要有交集的所有集合的更多相关文章
- delphi将两个Strlist合并,求交集 (保留相同的)
Function StrList_Join(StrListA,StrListB:String):String; //将两个Strlist合并,求交集 (保留相同的) var SListA,SListB ...
- Oracle 取两个表中数据的交集并集差异集合
Oracle 取两个表中数据的交集 关键字: Oracle 取两个表中数据的交集 INTERSECT Oracle 作为一个大型的关系数据库,日常应用中往往需要提取两个表的交集数据 例如现有如下表,要 ...
- 数据规整化:pandas 求合并数据集(交集并集等)
数据集的合并或连接运算是通过一个或多个键将行链接起来的.这些运算是关系型数据库的核心.pandas的merge函数是对数据应用这些算法的这样切入点. 默认是交集, inner连接 列名不同可以分别指定 ...
- List集合中的交集 并集和差集
目录 List集合求交集 并集 差集 Set集合 Lambda表达式 List集合求交集 并集 差集 两种方法求集 Set集合 交集 两个集合中有相同的元素 抽取出来的数据就是为交集 @Test pu ...
- Linq连接查询之左连接、右连接、内连接、全连接、交叉连接、Union合并、Concat连接、Intersect相交、Except与非查询
内连接查询 内连接与SqL中inner join一样,即找出两个序列的交集 Model1Container model = new Model1Container(); //内连接 var query ...
- 14.python中的集合
什么是集合?正如其字面的意思,一堆东西集中合并到一起.乍一听貌似和容器没什么差别,嗯,好吧,集合也算是一种容器. 在学习这个容器有什么不同之前,先看看集合是如何创建的: a = set() #可变集合 ...
- Python学习笔记四--字典与集合
字典是Python中唯一的映射类型.所谓映射即指该数据类型包含哈希值(key)和与之对应的值(value)的序列.字典是可变类型.字典中的数据是无序排列的. 4.1.1字典的创建及赋值 dict1={ ...
- (python)数据结构---集合
一.描述 set翻译为集合 set是可变的.无序的.不可重复的 set的元素要求可哈西(不可变的数据类型可哈西,可变的数据类型不可哈希) set是无序的,因此不可以索引,也不可以修改 线型结构的查询时 ...
- pythonj基础(五)元组和集合
一,什么是元祖 Python的元组与列表类似,不同之处在于元组的元素不能修改. 元组使用小括号,列表使用方括号. 元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可. 1.创建一个空元组 tu ...
随机推荐
- 6101 最优贸易 (双向spfa)
描述C国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分为双向通行的道路,双向通行的 ...
- 对Spring运用的一些思考
最近使用spring总是遇到启动时启动不起来,或者启动起来一会就服务就关闭掉. 停下来想想不是spring不好复杂,而是我对它掌握不够,再有就是使用要尽量规范 使用配置文件,dao.manager.s ...
- django——模板层
每一个Web框架都需要一种很便利的方法用于动态生成HTML页面. 最常见的做法是使用模板. 模板包含所需HTML页面的静态部分,以及一些特殊的模版语法,用于将动态内容插入静态部分. 说白了,模板层就是 ...
- [POJ2559]Largest Rectangle in a Histogram (栈)
题意 如图所示,在一条水平线上有n个宽为1的矩形,求包含于这些矩形的最大子矩形面积(图中的阴影部分的面积即所求答案). 思路 一个很老的,也是一个很好的题目. 维护一个单调栈即可. 不过在洛谷SP18 ...
- Vue(二十五)打包后路径报错问题
1.修改 config - index.js 2.修改 build - utils.js
- idea创建的java web项目打包发布到tomcat
File-> Project Structure... 点击Artifacts->+号 点击Web Application:Archive->选择与你的项目对应的那一项Artifac ...
- tomcat多实例
//结合博主之前的安装tomcat的博文一起看,tomcat多实例就是在不同路径启动多个tomcat,然后在本机不同端口启动 [root@ycj ~]# cd /usr/local/src/ [roo ...
- scheduling while atomic和bad: scheduling from the idle thread(转)
https://blog.csdn.net/shanzhizi/article/details/22949121 https://blog.csdn.net/wwwtovvv/article/deta ...
- 壁虎书6 Decision Trees
Decision Trees are versatile Machine Learning algorithms that can perform both classification and re ...
- fiddler修改Requests之前的数据和response 之后的数据
1. 开启抓包 file--->capture traffic 2. 在页面底部黑框输入bpu http://www.runoob.com/?s=mysql 3. 在浏览器URL输入http:/ ...