添加 '2.2.cpp'
This commit is contained in:
parent
0fcee9bc9a
commit
fb983c8e7d
105
2.2.cpp
Normal file
105
2.2.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
#include "MySQLWrapper.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
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);
|
||||
conn.exec("set names gbk",nullptr);
|
||||
|
||||
/// 2.2 不同领域的平均薪资
|
||||
vector<vector<string>> keywdvec
|
||||
{
|
||||
{
|
||||
"大数据"
|
||||
},
|
||||
{
|
||||
"程序开发","程序设计","开发"
|
||||
},
|
||||
{
|
||||
"运维","运行维护","维护"
|
||||
},
|
||||
{
|
||||
"测试"
|
||||
}
|
||||
};
|
||||
|
||||
map<string,vector<cash_pack>> mp;
|
||||
|
||||
int szArea=keywdvec.size();
|
||||
for(int i=0;i<szArea;i++)
|
||||
{
|
||||
int szAlias=keywdvec[i].size();
|
||||
for(int j=0;j<szAlias;j++)
|
||||
{
|
||||
ostringstream ostr;
|
||||
ostr<<"select salary from lagou_job where ((title like '%"
|
||||
<<keywdvec[i][j]<<"%') or (tags like '%"
|
||||
<<keywdvec[i][j]<<"%'))";
|
||||
|
||||
conn.exec("use bigdata3",nullptr);
|
||||
string sqlcmd=ostr.str();
|
||||
|
||||
conn.exec(sqlcmd,[&](MySQLResult& res)
|
||||
{
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
cash_pack pk=ParseCash(val[0]);
|
||||
mp[keywdvec[i][j]].push_back(pk);
|
||||
});
|
||||
});
|
||||
|
||||
ostr.str("");
|
||||
ostr<<"select salary from pages where ((title like '%"
|
||||
<<keywdvec[i][j]<<"%') or (tags like '%"
|
||||
<<keywdvec[i][j]<<"%'))";
|
||||
|
||||
sqlcmd=ostr.str();
|
||||
|
||||
conn.exec("use bigdata5",nullptr);
|
||||
conn.exec(sqlcmd,[&](MySQLResult& res)
|
||||
{
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
cash_pack pk=ParseCashX(val[0]);
|
||||
mp[keywdvec[i][j]].push_back(pk);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ofstream ofs("result/2.2.csv");
|
||||
#define cout ofs
|
||||
cout<<"行业,最低工资,最高工资,平均工资,数量"<<endl;
|
||||
for(auto& pr:mp)
|
||||
{
|
||||
int sum=0;
|
||||
int lowest=9999999;
|
||||
int highest=-1;
|
||||
int szVec=pr.second.size();
|
||||
for(auto& pk:pr.second)
|
||||
{
|
||||
sum+=pk.ave();
|
||||
lowest=min(lowest,pk.low);
|
||||
highest=max(highest,pk.high);
|
||||
}
|
||||
sum/=szVec;
|
||||
cout<<pr.first<<","<<lowest<<","<<highest<<","<<sum<<","<<szVec<<endl;
|
||||
}
|
||||
#undef cout
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user