set容器的查找和统计
2023-09-14 09:02:34 时间
查找和统计
#include<iostream>
using namespace std;
#include<set>
void p(set<int>& s)
{
for (set<int>::iterator it = s.begin(); it != s.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test()
{
set<int> s1 = {1,2,3};
//插入数据,只有用insert方式
s1.insert(4);
s1.insert(6);
s1.insert(6);
s1.insert(5);
p(s1);
//查找某一元素是否存在,存在就返回其迭代器,否则返回set.end()
set<int>::iterator it=s1.find(3);
if (it != s1.end())
cout << "该元素: " << *it << endl;
else
cout << "未找到该元素" << endl;
//统计某一个元素的个数
//对于set而言,结果只有0和1
int num = 0;
num = s1.count(3);
cout << "元素3的个数为:" << num << endl;
}
int main()
{
test();
system("pause");
return 0;
}
总结:
相关文章
- Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
- sqlplus 环境下部分set 命令
- Java常用数据结构之Set之TreeSet
- [Bash] Set Default Arguments with Bash Shell Parameter Expansions
- EasyPusher华为手机直播推流硬编码[OMX.IMG.TOPAZ.Encoder] failed to set input port definition parameters.
- Nginx proxy_set_header 理解
- set容器排序
- ABAP SET UPDATE TASK LOCAL的测试
- ABAP SET UPDATE TASK LOCAL的测试
- 使用jMeter的csv data set config避免用户密码的硬编码
- 全网详细介绍MySQL中的show variables like ‘%xxx%’、show global status like ‘%xxx%’ 和 set global ‘xxx’=value
- 【STL】set集合