SET函数总结
函数 | 功能 | 时间复杂度 | |||||
insert | 插入一个元素 | O(log n) | |||||
erase | 删除一个元素 | O(log n) | |||||
count | 统计集合中某个元素的个数 | O(log n) | |||||
size | 获取元素个数 | O(1) | |||||
clear | 清空 | O(n) |
参考代码:
#include<iostream> #include<set> using namespace std; int main(){ set<int>num; int k, x, n; cin >> k; for (int i = 0; i < k; i ++){ cin >> x >> n; if( x == 1){ num.insert(n); //向集合num中插入一个元素n(不会重复插入) }else if( x == 2){ if(num.count(n)){ //统计集合num中元素n的个数(返回 1(true)或者 0(false)) cout << "True" << endl; }else{ cout << "False" << endl; } } } return 0; }
0.0分
1 人评分
C二级辅导-统计字符 (C语言代码)浏览:533 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C++代码)(手动优化一下计算)浏览:1280 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:411 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:451 |
蛇行矩阵 (C语言代码)浏览:744 |
IP判断 (C语言代码)浏览:762 |
printf基础练习2 (C语言代码)浏览:746 |
蛇行矩阵 (C语言代码)浏览:524 |
1017题解浏览:592 |
Tom数 (C语言代码)浏览:525 |