107 lines
3.2 KiB
C++
107 lines
3.2 KiB
C++
#include "MySQLWrapper.h"
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <set>
|
|
#include <cstdlib>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
#include <fstream>
|
|
using namespace std;
|
|
|
|
#include "local_db_account.h"
|
|
#include "util.hpp"
|
|
|
|
int main()
|
|
{
|
|
/// 2.5 大数据在全国的岗位需求量分布
|
|
|
|
MySQLConn conn;
|
|
conn.connect("127.0.0.1",db_user,db_passwd,"bigdata3",3306);
|
|
cout<<"Connected to DB"<<endl;
|
|
conn.exec("set names gbk",nullptr);
|
|
|
|
map<string,vector<int>> mp;
|
|
conn.exec("select job_city,count(*) from lagou_job where ( ( title like '%大数据%' ) or ( tags like '%大数据%' ) ) 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 where ( ( title like '%大数据%' ) or ( tags like '%大数据%' ) ) 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 where ( title like '%大数据%' ) 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.5.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
|
|
|
|
cout<<"城市,大数据岗位数量"<<endl;
|
|
for(auto& pr:mp)
|
|
{
|
|
cout<<pr.first<<",";
|
|
int sum=0;
|
|
int n=pr.second.size();
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
sum+=pr.second[i];
|
|
}
|
|
cout<<sum<<endl;
|
|
}
|
|
|
|
#undef cout
|
|
|
|
return 0;
|
|
}
|