diff --git a/3.3.cpp b/3.3.cpp new file mode 100644 index 0000000..6beeaf2 --- /dev/null +++ b/3.3.cpp @@ -0,0 +1,116 @@ +#include "MySQLWrapper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "local_db_account.h" +#include "util.hpp" + +int main() +{ + /// 3.3 大数据岗位需求量前十个 + + MySQLConn conn; + conn.connect("127.0.0.1",db_user,db_passwd,"bigdata3",3306); + cout<<"Connected to DB"<>& mp) + { + 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; + } + + for(auto& pr:mp) + { + int sum=0; + int n=pr.second.size(); + for(int i=0; i + map> dmp; + + conn.exec("use bigdata3",nullptr); + conn.exec("select title,count(*) as want_num from lagou_job where ((title like '%大数据%' ) or ( tags like '%大数据%')) group by title order by want_num desc",[&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + string title(val[0]); + int cc=ParseInt(val[1]); + dmp[Trim(title)].push_back(cc); + }); + }); + + conn.exec("use bigdata5",nullptr); + conn.exec("select title,count(*) as want_num from pages where ((title like '%大数据%' ) or ( tags like '%大数据%')) group by title order by want_num desc",[&](MySQLResult& res) + { + res.stepRow([&](char** val,unsigned long* len) + { + string city(val[0]); + int cc=ParseInt(val[1]); + dmp[Trim(city)].push_back(cc); + }); + }); + + fn1(dmp); + + vector> vec; + for(const auto& pr:dmp) + { + vec.push_back(make_pair(pr.first,pr.second[0])); + } + sort(vec.begin(),vec.end(),[](const pair& a,const pair& b) + { + return a.second > b.second; + }); + + ofstream ofs("result/3.3.csv"); + #define cout ofs + int szLoop=min(10u,vec.size()); + for(int i=0;i