diff --git a/2.3.cpp b/2.3.cpp new file mode 100644 index 0000000..b4733e7 --- /dev/null +++ b/2.3.cpp @@ -0,0 +1,92 @@ +#include "MySQLWrapper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "local_db_account.h" +#include "util.hpp" + +int main() +{ + MySQLConn conn; + conn.connect("127.0.0.1",db_user,db_passwd,"bigdata3",3306); + cout<<"Connected to DB"<> mp; + conn.exec("select job_city,count(*) from lagou_job group by job_city",[&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + string city(val[0]); + int cc=ParseInt(val[1]); + mp[Trim(city)].push_back(cc); + }); + }); + + conn.exec("use bigdata5",nullptr); + conn.exec("select job_city,count(*) from pages group by job_city",[&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + string city(val[0]); + int cc=ParseInt(val[1]); + mp[Trim(city)].push_back(cc); + }); + }); + + ofstream ofs("result/2.3.csv"); + + for(auto iter=mp.begin();iter!=mp.end(); ) + { + bool updated=false; + for(auto xiter=mp.begin();xiter!=iter; ) + { + if(iter->first.find(xiter->first)!=string::npos) + { + /// Found something? + /// targetvec.push_back(thisvec) : Add current vector to the previous vector. + xiter->second.insert(xiter->second.end(), + iter->second.begin(),iter->second.end()); + + + /// iter should now be deleted. Get next iter first + auto nowiter=iter; + ++iter; + mp.erase(nowiter); + + /// Stop internal loop. + updated=true; + break; + } + else ++xiter; + } + + if(!updated) ++iter; + } + + #define cout ofs + + for(auto& pr:mp) + { + cout<