除去一部分交易形成的文件文件

2023-09-11 02:40:54 作者:残月絮辰

我有一个包含数据如下文件

I have a file containing data as follows

10 20 30 40 70 
20 30 70 
30 40 10 20 
29 70 
80 90 20 30 40 
40 45 65 10 20 80 
45 65 20 

我想从文件中删除所有的子集交易。

I want to remove all subset transaction from this file.

输出文件应该像如下

10 20 30 40 70 
29 70 
80 90 20 30 40
40 45 65 10 20 80 

在哪里像

20 30 70 
30 40 10 20 
45 65 20 

被删除,因为它们是其他记录集。

are removed because of they are subset of other records.

推荐答案

提示:最简单的方法是使用的的std ::设为

Hint: easiest way is to use std::set

#include <set>
#include <algorithm>

...

std::set< int > s1, s2;

...

// Is s1 a subset of s2?
bool test = std::includes(s2.begin(),s2.end(),s1.begin(),s1.end());

您可以创建一个集合的集合,然后做一个^ 2量包括测试,以删除重复。一定要检查它集较大,挑哪一个应该被删除。

You could create a set of sets, and then do a n^2 amount of include tests to remove the duplicates. Be sure to check which set is larger, to pick which one should be removed.

这是不是在最快办法做到这一点,但可能是最容易的。

This is not the fastest way to do it, but probably the easiest.

 
精彩推荐
图片推荐