#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) }}

  • find
  • sort
  • count
  • reverse

第 3 题

③处应填( )。

{{ select(3) }}

  • insert
  • resize
  • erase
  • reserve

第 4 题

④处应填( )。

{{ select(4) }}

  • lower_bound
  • upper_bound
  • find
  • unique

第 5 题

⑤处应填( )。

{{ select(5) }}

  • b
  • a
  • x
  • a.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 > ans
  • p.second > best
  • p.second < best
  • cnt.empty()

第 8 题

③处应填( )。

{{ select(8) }}

  • p.first
  • cnt.size()
  • p.second
  • best + 1

第 9 题

④处应填( )。

{{ select(9) }}

  • p.first
  • p.second
  • words.size()
  • ans.size()

第 10 题

⑤处应填( )。

{{ select(10) }}

  • best
  • cnt
  • words
  • ans

程序三:统计闭区间元素个数

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) }}

  • sort
  • count
  • find
  • clear

第 12 题

②处应填( )。

{{ select(12) }}

  • upper_bound
  • lower_bound
  • min_element
  • unique

第 13 题

③处应填( )。

{{ select(13) }}

  • lower_bound
  • find
  • upper_bound
  • reverse

第 14 题

④处应填( )。

{{ select(14) }}

  • left-right
  • a.size()
  • right-left
  • *right-*left

第 15 题

⑤处应填( )。

{{ select(15) }}

  • a
  • right
  • left
  • answer