girija_cv
asked on
multimap
I have 2 input files xx.txt & yy.txt
contents of xx.txt are as follows
Aardenburg,,34394,512775,4 527
Aardenburg,,30000,500000,4 527
fields are city,cu,x,y,poco
contents of yy.txt are as follows
4527 AA,AARDENBURG
4527 AB,AARDENBURG
4553 AA,PHILIPPINE
4553 AB,PHILIPPINE
4555 xx,girija
fields are poco & city.
I want to match 4 digit poco & city of yy.txt with poco & city of xx.txt.if they are matched 7digit poco of yy.txt should be appennded.output should be as follows.
Aardenburg,,34394,512775,4 527,@4527 AA@4527 AB
Aardenburg,,30000,500000,4 527,@4527 AA@4527 AB
the coding is as follows
#include <map>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <conio.h>
#include <list>
using namespace std;
typedef multimap<string,string> yy;
void process_yy(yy &);
void process_xx(yy &);
string toUpper(string strText)
{
transform(strText.begin(), strText.end(), strText.begin(), toupper);
return strText;
}
int main( )
{
yy YY;
process_yy(YY);
process_xx(YY);
}
void process_xx(yy &YY)
{
list<string> list1;
ifstream f_road("xx.txt");
string line_str,str_element,ct,p;
string city,poco,cu,x,y,add;
string xx_cu_key,xx_key;
int i,j;
typedef pair <string, string> Int_Pair;
multimap<string,string>::i terator it;
multimap<string,string>::i terator it1;
multimap<string,string>::i terator last_el;
multimap<string,string>::i terator last_el1;
ofstream f_match("match.txt");
ofstream f_nomatch("nomatch.txt");
while(getline(f_road,line_ str))
{
std::istringstream istr(line_str);
getline(istr,city,',');
getline(istr,cu,',');
getline(istr,x,',');
getline(istr,y,',');
getline(istr,poco,',');
string city_org,cu_org;
cu_org=cu;city_org=city;
city = toUpper(city_org);
cu=toUpper(cu_org);
xx_key.clear();
xx_cu_key.clear();
city.append(poco);
cu.append(poco);
it=YY.find(city);
if(it!=YY.end())
{
last_el=YY.upper_bound(cit y);
last_el1=YY.upper_bound(ci ty);
for(;it!=last_el;it++)
{
add = it->second;
std::istringstream istr1(add);
getline(istr1,ct,',');
getline(istr1,p,',');
list1.push_back('@'+p);
//ParmsList.push_back('@'+ p);
}
f_match<<city_org<<','<<cu _org<<','< <x<<','<<y <<','<<poc o<<',';
cout<<city<<','<<cu<<','<< x<<','<<y< <','<<poco <<','<<it- >second<<' ,' ;
copy (list1.begin(),list1.end() ,std::ostr eam_iterat or<std::st ring>(f_ma tch));
f_match<<"\n";
list1.clear();
}
else
{
f_nomatch<<city_org<<','<< cu_org<<', '<<x<<','< <y<<','<<p oco<<"\n";
}
}
}
}
void process_yy(yy & YY)
{
ifstream f_road("yy.txt");
string line_str,str_element;
string city,poco_n,poco,yy_key;
typedef pair <string, string> Int_Pair;
while(getline(f_road,line_ str))
{
std::istringstream istr(line_str);
getline(istr,poco_n,',');
getline(istr,city,',');
poco= poco_n.substr(0,4);
yy_key=city+poco;
city = city + ',' + poco_n;
YY.insert(Int_Pair(yy_key, city));
}
multimap<string,string>::i terator it;
/*it=m_roadmap.find("Abc") ;
if(it!=m_roadmap.end())
{
cout<<"found";
}*/
for(it=YY.begin();it!=YY.e nd();it++)
{
cout<<it->first<<"\n";
cout<<it->second<<"\n";
}
}
but it prints the o/p as follows.
Aardenburg,,34394,512775,4 527,@4527 AA@4527 AB
can anyone giude me?
contents of xx.txt are as follows
Aardenburg,,34394,512775,4
Aardenburg,,30000,500000,4
fields are city,cu,x,y,poco
contents of yy.txt are as follows
4527 AA,AARDENBURG
4527 AB,AARDENBURG
4553 AA,PHILIPPINE
4553 AB,PHILIPPINE
4555 xx,girija
fields are poco & city.
I want to match 4 digit poco & city of yy.txt with poco & city of xx.txt.if they are matched 7digit poco of yy.txt should be appennded.output should be as follows.
Aardenburg,,34394,512775,4
Aardenburg,,30000,500000,4
the coding is as follows
#include <map>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <conio.h>
#include <list>
using namespace std;
typedef multimap<string,string> yy;
void process_yy(yy &);
void process_xx(yy &);
string toUpper(string strText)
{
transform(strText.begin(),
return strText;
}
int main( )
{
yy YY;
process_yy(YY);
process_xx(YY);
}
void process_xx(yy &YY)
{
list<string> list1;
ifstream f_road("xx.txt");
string line_str,str_element,ct,p;
string city,poco,cu,x,y,add;
string xx_cu_key,xx_key;
int i,j;
typedef pair <string, string> Int_Pair;
multimap<string,string>::i
multimap<string,string>::i
multimap<string,string>::i
multimap<string,string>::i
ofstream f_match("match.txt");
ofstream f_nomatch("nomatch.txt");
while(getline(f_road,line_
{
std::istringstream istr(line_str);
getline(istr,city,',');
getline(istr,cu,',');
getline(istr,x,',');
getline(istr,y,',');
getline(istr,poco,',');
string city_org,cu_org;
cu_org=cu;city_org=city;
city = toUpper(city_org);
cu=toUpper(cu_org);
xx_key.clear();
xx_cu_key.clear();
city.append(poco);
cu.append(poco);
it=YY.find(city);
if(it!=YY.end())
{
last_el=YY.upper_bound(cit
last_el1=YY.upper_bound(ci
for(;it!=last_el;it++)
{
add = it->second;
std::istringstream istr1(add);
getline(istr1,ct,',');
getline(istr1,p,',');
list1.push_back('@'+p);
//ParmsList.push_back('@'+
}
f_match<<city_org<<','<<cu
cout<<city<<','<<cu<<','<<
copy (list1.begin(),list1.end()
f_match<<"\n";
list1.clear();
}
else
{
f_nomatch<<city_org<<','<<
}
}
}
}
void process_yy(yy & YY)
{
ifstream f_road("yy.txt");
string line_str,str_element;
string city,poco_n,poco,yy_key;
typedef pair <string, string> Int_Pair;
while(getline(f_road,line_
{
std::istringstream istr(line_str);
getline(istr,poco_n,',');
getline(istr,city,',');
poco= poco_n.substr(0,4);
yy_key=city+poco;
city = city + ',' + poco_n;
YY.insert(Int_Pair(yy_key,
}
multimap<string,string>::i
/*it=m_roadmap.find("Abc")
if(it!=m_roadmap.end())
{
cout<<"found";
}*/
for(it=YY.begin();it!=YY.e
{
cout<<it->first<<"\n";
cout<<it->second<<"\n";
}
}
but it prints the o/p as follows.
Aardenburg,,34394,512775,4
can anyone giude me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> 20 points is not going to get you far ...
I learned from one of your previous questions that could not give more points as you have no more left. I suppose, you know that you could get more points if you spend some money to EE.. Also, you already spend a lot of points not getting a final solution to your task. The reason for this is your input files that always are changing from question to question and most of your problems you only got because your code doesn't reflect these changes. If you had given us a good spec, two input file definitions that would hold longer than a day and say 300 points some weeks before, you would have now a better solution and still points left.
Regards, Alex
BTW, if you would post here a final spec, i would show you a much better coding than that you have til now. And i don't need more points... ;-)
I learned from one of your previous questions that could not give more points as you have no more left. I suppose, you know that you could get more points if you spend some money to EE.. Also, you already spend a lot of points not getting a final solution to your task. The reason for this is your input files that always are changing from question to question and most of your problems you only got because your code doesn't reflect these changes. If you had given us a good spec, two input file definitions that would hold longer than a day and say 300 points some weeks before, you would have now a better solution and still points left.
Regards, Alex
BTW, if you would post here a final spec, i would show you a much better coding than that you have til now. And i don't need more points... ;-)
Give the points to itsmeandnobodyelse
I understand that your problem is that the multimap is not containing all records, so check the place where you insert these records and print a trace just before the insert and afterwards check if it was inserted.
I suggest that first you use C++ as you should and encapsulate reading from each file.
Then apply the processes to the adecuate object.
It will be much easier to debug and maintain.