#P1401. Day3.5 STL 阅读与完善程序(12题)
Day3.5 STL 阅读与完善程序(12题)
第 1 题
写出程序输出(只填数字,连续填写)。
vector<int> a={3,1,4}; a.push_back(2); sort(a.begin(),a.end()); for(int x:a) cout<<x;
{{ input(1) }}
第 2 题
写出程序输出(只填数字)。
vector<int> a={1,2,3}; for(int x:a) x*=2; cout<<a[1];
{{ input(2) }}
第 3 题
写出程序输出(只填数字)。
vector<int> a={1,2,3}; for(int &x:a) x*=2; cout<<a[1];
{{ input(3) }}
第 4 题
写出程序输出(只填数字,连续填写)。
vector<pair<int,int>> a={{2,3},{1,9},{2,1}}; sort(a.begin(),a.end()); for(auto p:a) cout<<p.second;
{{ input(4) }}
第 5 题
写出程序输出(只填数字)。
set<int> s={4,2,4,1,2}; cout<<s.size();
{{ input(5) }}
第 6 题
写出程序输出(只填数字)。
map<char,int> m; string s="abac"; for(char c:s)m[c]++; cout<<m['a'];
{{ input(6) }}
第 7 题
补全代码:在vector尾部加入x,应填写哪个成员函数名(不写括号)? {{ input(7) }}
第 8 题
补全代码:从小到大排序 sort(a.____(),a.end());,空中填什么?
{{ input(8) }}
第 9 题
补全代码:第一个大于等于x的位置使用哪个算法名? {{ input(9) }}
第 10 题
补全代码:删除set中的x,应使用哪个成员函数名? {{ input(10) }}
第 11 题
补全代码:判断map中键key是否存在,可使用 mp.____(key) 并与 mp.end() 比较。
{{ input(11) }}
第 12 题
以下代码 vector<int> a; cout<<a.back(); 的主要问题是( )。
{{ select(12) }}
- vector为空时访问back越界
- 不能声明vector
- push_back语法错误
- size不能使用