views:

93

answers:

1

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.

output file should be like follows

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

Where records like

20 30 70
30 40 10 20
45 65 20

are removed because of they are subset of other records.

+1  A: 

Hi, the algorithm could be like this:

sets = list()
f = open("data.txt")

for line in f:
    currentSet = set()
    for item in line.split():
        currentSet.add(int(item))
    printIt = True
    for s in sets:
        if currentSet.issubset(s):
            printIt = False
            break
    if printIt:
        print line,
        sets.append(currentSet)

Incidentally, this is also a Python program :) Also I believe that an algorithm with better effeciency could be made.

Your next step: rewrite this to C/C++. Good luck :)

Messa
Giving an algorithm in the wrong language is a nice answer to a give-me-the-code question. Here, have a cookie. `:)`
sbi
please can you help how to code it in c/c++ please help me!