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 ...
随机推荐
- B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)
---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integ ...
- linux打包文件和压缩
1.解压:tar -zxvf archive.tar , unzip file1.zip 2.压缩:tar -cvfz archive.tar.gz dir1 , zip file1.zip file ...
- SDOI2018:原题识别
题解: https://files.cnblogs.com/files/clrs97/old-solution.pdf Code: #include<cstdio> #include< ...
- Thinkphp3.2.3加载外部类并调用类里面的方法 获取token
例如:加载七牛上传类(thinkphp自带的) $qiniu = new \Think\Upload\Driver\Qiniu\QiniuStorage($setting['driverConfig' ...
- 07_ for 练习 _ sumOfOdd
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- [LeetCode] Minimum Swaps To Make Sequences Increasing 使得序列递增的最小交换
We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...
- js 快速将字符串数组 转化为 数字数组(互换)
转载于 这里 var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.map(String); //结果: ['1', '2', '3', '4', '5', '6' ...
- Eclipse导出自己的项目(仅供自己保留方式war包)
War: Jar包:
- jenkins-参数化构建(二)插件:Extended Choice Parameter
一.Extended Choice Parameter插件 这个插件相对丰富,安装过程就不过多介绍了,在点击项目设置后会出现下载的插件名字. 写在文件中构建时效果如下:
- LeetCode 33 - 搜索旋转排序数组 - [二分]
假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这个目标值, ...