更新 '3.2.cpp'
This commit is contained in:
parent
a017dfc5a5
commit
ac37db4028
83
3.2.cpp
83
3.2.cpp
@ -116,6 +116,17 @@ int main()
|
||||
});
|
||||
});
|
||||
|
||||
conn.exec("use bigdata2",nullptr);
|
||||
conn.exec("select title,count(*) as want_num from pages where title 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<pair<string,vector<int>>> city_vec;
|
||||
@ -156,20 +167,6 @@ int main()
|
||||
int szCity=city_vec.size();
|
||||
int szJob=job_vec.size();
|
||||
|
||||
auto fn2=[&conn](const string& cmd,int& cc){
|
||||
conn.exec(cmd,[&](MySQLResult& res)
|
||||
{
|
||||
bool done=false;
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
if(!done)
|
||||
{
|
||||
cc=ParseInt(val[0]);
|
||||
done=true;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
for(int i=0;i<szCity;i++)
|
||||
{
|
||||
@ -178,21 +175,69 @@ int main()
|
||||
cout<<"i:"<<i<<"("<<city_vec[i].first<<") j:"<<j<<"("<<job_vec[j].first<<") "<<endl;
|
||||
|
||||
ostringstream ostm;
|
||||
ostm << "select count(*) from lagou_job where ((job_city like '%"
|
||||
ostm << "select count(*) from lagou_job where ( (job_city = '"
|
||||
<<city_vec[i].first
|
||||
<<"%') and (title like '%"
|
||||
<<"' ) and (title like '%"
|
||||
<<job_vec[j].first <<"%'))";
|
||||
|
||||
string cmd=ostm.str();
|
||||
|
||||
conn.exec("use bigdata3",nullptr);
|
||||
int c1=0;
|
||||
conn.exec(cmd,[&](MySQLResult& res)
|
||||
{
|
||||
bool done=false;
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
if(!done)
|
||||
{
|
||||
c1=ParseInt(val[0]);
|
||||
done=true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
ostm.str("");
|
||||
ostm << "select count(*) from pages where ( (job_city = '"
|
||||
<<city_vec[i].first
|
||||
<<"' ) and (title like '%"
|
||||
<<job_vec[j].first <<"%'))";
|
||||
|
||||
cmd=ostm.str();
|
||||
|
||||
fn2(cmd,c1);
|
||||
conn.exec("use bigdata5",nullptr);
|
||||
int c2=0;
|
||||
fn2(cmd,c2);
|
||||
conn.exec(cmd,[&](MySQLResult& res)
|
||||
{
|
||||
bool done=false;
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
if(!done)
|
||||
{
|
||||
c2=ParseInt(val[0]);
|
||||
done=true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tvec[i][j]=c1+c2;
|
||||
conn.exec("use bigdata2",nullptr);
|
||||
int c3=0;
|
||||
conn.exec(cmd,[&](MySQLResult& res)
|
||||
{
|
||||
bool done=false;
|
||||
res.stepRow([&](char** val,unsigned long* len)
|
||||
{
|
||||
if(!done)
|
||||
{
|
||||
c3=ParseInt(val[0]);
|
||||
done=true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
tvec[i][j]=c1+c2+c3;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user