| 1 |
#include <string> |
| 2 |
#include <fstream> |
| 3 |
#include <iostream> |
| 4 |
#include <vector> |
| 5 |
#include <map> |
| 6 |
using namespace std; |
| 7 |
typedef pair<double,double> Point; |
| 8 |
int main(void) |
| 9 |
{ |
| 10 |
ifstream location_file("london-locations.csv"), path_file("london.txt"); |
| 11 |
string id,sx,sy; |
| 12 |
map<string,Point> idlookup; |
| 13 |
while (getline(location_file,id,',')) |
| 14 |
{ |
| 15 |
getline(location_file,sx,','); |
| 16 |
getline(location_file,sy,'\n'); |
| 17 |
char *e; |
| 18 |
double x = strtod(sx.c_str(),&e), y = strtod(sy.c_str(),&e); |
| 19 |
cout << id << " (" << x << "," << y << ")"<< endl; |
| 20 |
idlookup[id]=make_pair(x,y); |
| 21 |
} |
| 22 |
string l; |
| 23 |
vector<vector<Point> > paths; |
| 24 |
while (getline(path_file,l,'\n')) { |
| 25 |
vector<Point> ps; |
| 26 |
if(l.size() < 2) continue; // skip blank lines |
| 27 |
if(l.find(":",0)!=string::npos) continue; // skip labels |
| 28 |
string::size_type p=0,q; |
| 29 |
while((q=l.find(",",p))!=string::npos || p < l.size() && (q = l.size()-1)) { |
| 30 |
id = l.substr(p,q-p); |
| 31 |
cout << id << ","; |
| 32 |
ps.push_back(idlookup[id]); |
| 33 |
p=q+1; |
| 34 |
} |
| 35 |
paths.push_back(ps); |
| 36 |
cout << "*******************************************" << endl; |
| 37 |
} |
| 38 |
for(unsigned i=0;i<paths.size();i++) { |
| 39 |
vector<Point> ps=paths[i]; |
| 40 |
for(unsigned j=0;j<ps.size();j++) { |
| 41 |
double x=ps[j].first, y=ps[j].second; |
| 42 |
cout << "(" << x << "," << y << ")" << ","; |
| 43 |
} |
| 44 |
cout << endl; |
| 45 |
} |
| 46 |
return(0); |
| 47 |
} |