Remember the key to actually merging the files is to process them both at once.
Now, the two remaining issues are still: 1) Do away with those extra commas and 2) Replace colon ':' with exclamation mark '!'.
You could also throw a regular expression at the problem. C++11 added a regex library to the standard. If you're using MSVC++ 2010 you have it. I managed to use this with lots of success:
Code:
#include <regex>
#include <string>
#include <sstream>
using namespace std;
string process_line(string line)
{
regex tokenRegex("\\d+:\\d+,|\\d+:\\d+$|\\d+:\\d+\.\\d+,|\\d+:\\d+\.\\d+$");
sregex_iterator tokensBegin(line.begin(), line.end(), tokenRegex);
sregex_iterator tokensEnd;
ostringstream builder;
for ( sregex_iterator i = tokensBegin; i != tokensEnd; i++ )
{
string match = (*i).str();
string::size_type where = match.find(':');
match[where] = '!';
builder << match;
}
string result = builder.str();
if (!result.empty() && result.back() == ',')
result.pop_back();
return result;
}
Running it on both files, I managed to produce:
Code:
1 1!4,2!5,3!7,4!4,5!7 5!1.0
2 1!4,2!3,3!6,4!4,5!6 1!1.0,4!1.0
3 1!4,2!4,3!7,4!4,5!7 2!1.0,3!1.0
4 1!2,3!5,4!7,5!4,8!3 3!1.0,8!1.0
5 2!3,4!4,5!7 4!1.0
6 1!4,3!7,4!6 5!1.0
7
8 2!4,8!7 2!1.0
9 3!1,4!4,6!7 3!1.0
10 1!5,2!8 4!1.0,7!1.0
11 1!1,2!5 3!1.0,4!1.0,5!1.0
12 3!4,4!5,6!8 1!1.0,5!1.0
Python also does regex and has for a long time...