|
-
January 24th, 2007, 12:23 AM
#1
regroup the data in a text file
Hi there:
I want to generate an algorithm to regroup the same data in a text file. There is a text file, for example, having the following data:
1 1 0.720 2.500 2.300 0.000 0.000 0.000
1 1 0.720 2.500 2.300 0.000 0.000 0.000
1 0 0.100 0.100 4.000 3.800 0.000 0.000
1 0 0.100 0.100 4.000 3.800 0.000 0.000
1 1 0.075 1.500 1.400 0.000 0.000 0.000
1 1 0.075 1.500 1.400 0.000 0.000 0.000
1 1 0.075 1.500 1.400 0.000 0.000 0.000
The algorithm reads these data from text file and regroups them into different groups (each group has the same data, in this example, there are 3 different groups) and stores their group index into an array. The algorithm should be able to automatically find out the number of groups and the group index of each line. The algorithm should obtain the group information in the right colume for these data:
1 1 0.720 2.500 2.300 0.000 0.000 0.000 Group 1
1 1 0.720 2.500 2.300 0.000 0.000 0.000 Group 1
1 0 0.100 0.100 4.000 3.800 0.000 0.000 Group 2
1 0 0.100 0.100 4.000 3.800 0.000 0.000 Group 2
1 1 0.075 1.500 1.400 0.000 0.000 0.000 Group 3
1 1 0.075 1.500 1.400 0.000 0.000 0.000 Group 3
1 1 0.075 1.500 1.400 0.000 0.000 0.000 Group 3
I know I could use ifstream, string and getline to open the file and get line by line data into string and compare the buffer of string. But it is difficult to regroup those lines having the same data into different groups.
Someone can give me some suggestion for this algorithm? Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|