Problem D: [CSP-S1][选择] STL容器2
Description
1. 下列哪个操作可能导致迭代器失效?( )
A. vector 的 push_back
B. set 的 find
C. map 的 count
D. queue 的 push
2. 以下代码的输出是( )。
priority_queue<int> pq;
pq.push(3);
pq.push(1);
pq.push(2);
cout << pq.top();
A. 1
B. 2
C. 3
D. 未定义
3. 若需维护一个有序且不重复的元素集合,应选择( )。
A. vector
B. unordered_set
C. set
D. multiset
4. 以下代码的输出是( )。
string s = "hello";
reverse(s.begin() s.end());
cout << s;
A. "hello"
B. "olleh"
C. "h e l l o"
D. 编译错误
5. 在STL中,pair 的主要用途是( )。
A. 存储两个相关联的值
B. 实现动态数组
C. 替代指针
D. 管理内存
6. 以下代码的输出是( )。
vector<int> v = {5 2 8};
sort(v.begin() v.end());
cout << v[1];
A. 5
B. 2
C. 8
D. 未排序
7. 下列哪个容器底层基于红黑树实现?( )
A. unordered_map
B. vector
C. map
D. queue
8. 若需频繁在序列中间插入元素,应避免使用( )。
A. list
B. vector
C. deque
D. set
9. 以下代码的输出是( )。
set<int> s = {3 1 4};
auto it = s.lower_bound(2);
cout << *it;
A. 1
B. 2
C. 3
D. 4
10. 在C++17中,遍历 map 的推荐方式是( )。
A.
for (auto it = mp.begin(); it != mp.end(); ++it)
B.
for (auto &[key val] : mp)
C.
for (auto elem : mp)
D.
for (int i = 0; i < mp.size(); i++)
Sample Input Copy
Sample Output Copy