Input text file, compare integer patterns, output new text file

Hello, Collective Wisdom,

I have a text file with many rows of numbers. Each line is 11 integers (all between 0-11), a colon, and then 12 more integers. It looks something like this:

1 1 1 1 1 1 1 1 1 1 1 : 0 11 10 9 8 7 6 5 4 3 2 1
2 1 2 1 1 1 1 1 1 1 1 : 0 10 11 9 8 7 6 5 4 3 2 1
1 2 1 2 1 1 1 1 1 1 1 : 0 11 9 10 8 7 6 5 4 3 2 1
1 1 2 1 2 1 1 1 1 1 1 : 0 11 10 8 9 7 6 5 4 3 2 1
10 11 10 11 11 11 11 11 11 11 11 : 0 2 1 3 4 5 6 7 8 9 10 11
etc (many more lines like these)

Basically, I just want to write a C++ program that will take this text file as input, and create a new text file, with certain rows eliminated.

My criteria for deletion will be this: if there are two rows where the first 11 number series are complements of each other, mod12, then delete one of the rows. Example: since the first number of Row #2 and the first number of Row #5 add up to 12 (that's what I mean by mod12 complements...forgive me if this is incorrect mathematical terminology), as do their second, third...eleventh numbers, Row #5 should be eliminated.

Loop through the list, comparing each line (left of colon only) to each previous line -- if RowX[y] = 12-RowZ[y] for all 11 entries, throw out RowX. If it has not appeared anywhere, keep it.

(The numbers to the RIGHT of the colon are not important for my purposes right now, but will be later...so they should still appear in the new text file)

I'm really stuck on this one...new to C++.
Thanks for your help!
Zachary
First, make a fstream, then open the file. Read the file into a vector<string> using getline(). Then, go through each line and parse if for the spaces, ignoring the stuff after the : basically, using string.find() and string.substr() to put each line into another vector < vector< int> > (a vector of a vector of ints). Then you can do your comparison stuff. You can look up all the functions on this site (except maybe string -> int stuff...for that, use stringstreams)
Topic archived. No new replies allowed.