除去一部分交易形成的文件 [英] removing subset transactions form file

查看:94
本文介绍了除去一部分交易形成的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于除去一部分交易形成的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆