how to remove subsets form given text file
Posted
by user324887
on Stack Overflow
See other posts from Stack Overflow
or by user324887
Published on 2010-05-13T07:29:27Z
Indexed on
2010/05/13
7:34 UTC
Read the original article
Hit count: 240
c++
i have a problem like this
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. i AM using set for this but i am not able to create one set for one line can anybody know how to do this please help me here i am sending you my code
include
include
include
using namespace std;
using namespace std;
set s1;
int main()
{
FILE fp = fopen ( "abc.txt", "r" ); if ( fp != NULL ) { char line [ 128 ]; / or other suitable maximum line size */
while ( fgets ( line, sizeof line, fp ) != NULL ) /* read a line */
{
istringstream iss(line);
do
{
string sub;
iss >> sub;
s1.insert(sub);
} while (iss);
for (set<string>::const_iterator p = s1.begin( );p != s1.end( ); ++p)
cout << *p << endl;
}
}
}
© Stack Overflow or respective owner