关注
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string>
using namespace std;
bool cmp(int i, int j) { return i<j; }
vector<double> BatchQueryExecutionTime
(const vector<string>&sqls, const vector<double>×, const vector<string>&keywords) {
vector<double> res;
if(!sqls.size() || !times.size() || !keywords.size())
return res;
vector< map<string, double> > mymaps(sqls.size());
int i = 0;
for(auto &it : sqls) {
string x = it;
stringstream ss(x);
while(ss>>x){
// x.erase(find(begin(x), end(x), '"'));
mymaps[i][x] = times[i];
}
++i;
}
for(auto &it : keywords) {
double sum = 0;
int cnt = 0;
for(auto &my_it : mymaps) {
if(my_it[it]) {
sum += my_it[it];
cnt++;
}
}
if(cnt)
res.push_back(sum/cnt);
else
res.push_back(0);
}
return res;
}
int main(void)
{
#ifdef LOCAL_PROJECT
freopen ("input.txt", "r", stdin);
//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
// add i/o method of specific testing system
#endif
vector<string> sqls;
sqls.push_back(" insert into tableA values (1, \"columnA\", \"columnB\")");
sqls.push_back(" insert into tableB values (2, \"columnA\", \"columnB\", \"columnC\")");
sqls.push_back("select columnA, columnC from tableB");
vector<double> times, res;
times.push_back(2.5);
times.push_back(12.5);
times.push_back(30);
vector<string> keywords;
keywords.push_back("tableB");
keywords.push_back("insert");
keywords.push_back("select");
keywords.push_back("0");
keywords.push_back("table");
keywords.push_back("tableA");
res = BatchQueryExecutionTime(sqls, times, keywords);
for(auto &it : res)
cout<<it<<endl;
return 0;
}
查看原帖
点赞 2
相关推荐
点赞 评论 收藏
分享

点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 我的实习收获 #
32803次浏览 513人参与
# 安利/避雷我的专业 #
73501次浏览 514人参与
# 实习吐槽大会 #
35553次浏览 164人参与
# 2025牛客秋招季 #
5392次浏览 165人参与
# 晒一晒你的工位 #
86487次浏览 307人参与
# 移动求职进展汇总 #
1626次浏览 17人参与
# 第一份工作应该选高薪还是热爱? #
61675次浏览 561人参与
# 我的租房踩坑经历 #
30915次浏览 312人参与
# 求职遇到的搞笑事件 #
113296次浏览 770人参与
# 我的国央企投递进展 #
43090次浏览 268人参与
# 26届秋招投递记录 #
4417次浏览 117人参与
# 穿越回高考你还会选现在的专业吗 #
23133次浏览 271人参与
# 地方国企笔面经互助 #
29979次浏览 98人参与
# 双非能在秋招上岸吗? #
215346次浏览 1144人参与
# 你后悔选择现在的专业吗 #
81776次浏览 670人参与
# 招银网络求职进展汇总 #
113281次浏览 741人参与
# 你觉得专业和学校哪个对薪资影响最大 #
57949次浏览 471人参与
# 毕业旅行去哪玩儿 #
1361次浏览 33人参与
# 如果有时光机,你最想去到哪个年纪? #
47268次浏览 800人参与
# 非技术岗简历怎么写 #
209900次浏览 2861人参与