#P1398. Day3.5 STL pair 与常用算法(12题)
Day3.5 STL pair 与常用算法(12题)
第 1 题
访问pair的两个成员,应使用( )。
{{ select(1) }}
- first和second
- left和right
- x和y固定
- begin和end
第 2 题
写出程序输出(只填数字,两个数空格分隔)。
pair<int,int> p={3,8}; cout<<p.first<<' '<<p.second;
{{ input(2) }}
第 3 题
pair默认比较顺序是( )。
{{ select(3) }}
- 先比较first,first相同再比较second
- 只比较second
- 只比较first
- 不能比较
第 4 题
写出程序输出(只填数字,连续填写)。
vector<pair<int,int>> a={{2,1},{1,5},{1,3}}; sort(a.begin(),a.end()); for(auto p:a) cout<<p.second;
{{ input(4) }}
第 5 题
STL算法常用的区间 [begin,end) 表示( )。
{{ select(5) }}
- 包含begin,不包含end
- 不包含begin,包含end
- 两端都包含
- 两端都不包含
第 6 题
写出程序输出(只填数字,连续填写)。
vector<int> a={4,1,3,2}; sort(a.begin(),a.end()); for(int x:a) cout<<x;
{{ input(6) }}
第 7 题
将vector按从大到小排序,常用( )。
{{ select(7) }}
sort(a.begin(),a.end(),greater<int>())sort(a.end(),a.begin())reverse(a.begin(),a.begin())find(a.begin(),a.end())
第 8 题
写出程序输出(只填数字,连续填写)。
vector<int> a={1,2,3,4}; reverse(a.begin(),a.end()); for(int x:a) cout<<x;
{{ input(8) }}
第 9 题
find 没找到目标时返回( )。
{{ select(9) }}
- 区间的end迭代器
- -1固定
- 0固定
- 最后一个元素
第 10 题
写出程序输出(只填数字)。
vector<int> a={2,1,2,3,2}; cout<<count(a.begin(),a.end(),2);
{{ input(10) }}
第 11 题
写出程序输出(只填数字)。
vector<int> a={7,2,9,4}; cout<<*min_element(a.begin(),a.end());
{{ input(11) }}
第 12 题
排序后删除重复元素的常见写法是( )。
{{ select(12) }}
a.erase(unique(a.begin(),a.end()),a.end())a.clear()a.erase(a.begin())- 只调用
unique即可自动缩小size