#P1405. Day3.5 STL 完善程序专项(15题)
Day3.5 STL 完善程序专项(15题)
Day3.5 STL 完善程序专项
三段程序均含关键空位,先判断整体功能和每个空位的角色,再选择答案。
程序一:合并并去重
vector<int> mergeDistinct(vector<int> a, const vector<int>& b) {
for (int x : b) {
__①__;
}
__②__(a.begin(), a.end());
a.__③__(__④__(a.begin(), a.end()), a.end());
return __⑤__;
}
第 1 题
①处应填( )。
{{ select(1) }}
a.push_back(x)a.pop_back()b.push_back(x)a.clear()
第 2 题
②处应填( )。
{{ select(2) }}
findsortcountreverse
第 3 题
③处应填( )。
{{ select(3) }}
insertresizeerasereserve
第 4 题
④处应填( )。
{{ select(4) }}
lower_boundupper_boundfindunique
第 5 题
⑤处应填( )。
{{ select(5) }}
baxa.size()
程序二:最高词频且字典序最小
string solve(const vector<string>& words) {
map<string, int> cnt;
for (const string& s : words) {
__①__;
}
int best = -1;
string ans = "";
for (const auto& p : cnt) {
if (__②__) {
best = __③__;
ans = __④__;
}
}
return __⑤__;
}
第 6 题
①处应填( )。
{{ select(6) }}
cnt[s]++cnt.clear()cnt.erase(s)s++
第 7 题
②处应填( )。
{{ select(7) }}
p.first > ansp.second > bestp.second < bestcnt.empty()
第 8 题
③处应填( )。
{{ select(8) }}
p.firstcnt.size()p.secondbest + 1
第 9 题
④处应填( )。
{{ select(9) }}
p.firstp.secondwords.size()ans.size()
第 10 题
⑤处应填( )。
{{ select(10) }}
bestcntwordsans
程序三:统计闭区间元素个数
int countRange(vector<int> a, int L, int R) {
__①__(a.begin(), a.end());
auto left = __②__(a.begin(), a.end(), L);
auto right = __③__(a.begin(), a.end(), R);
int answer = __④__;
return __⑤__;
}
第 11 题
①处应填( )。
{{ select(11) }}
sortcountfindclear
第 12 题
②处应填( )。
{{ select(12) }}
upper_boundlower_boundmin_elementunique
第 13 题
③处应填( )。
{{ select(13) }}
lower_boundfindupper_boundreverse
第 14 题
④处应填( )。
{{ select(14) }}
left-righta.size()right-left*right-*left
第 15 题
⑤处应填( )。
{{ select(15) }}
arightleftanswer