STL之<set>

来源:互联网 发布:python爬虫识别验证码 编辑:程序博客网 时间:2024/04/30 06:06





Set用于存储不重复的元素,若重复存入同一元素,则set会将其覆盖掉。#include <iostream>#include <set>using namespace std;set <int> h;//这个地方的int可以换为任意你想储存元素的类型int main() {    int n, x;    cin >> n;
    h.clear();//这条语句的目的是清理h;    for(int i = 0; i < n; i++) {        cin >> x;        h.insert(x);    }    set <int>::iterator it;    for(it = h.begin(); it != h.end(); it++)        cout << (*it) << endl;    if(h.find(3) != h.end())  cout << "Yes, 3 is in set h" << endl;    else  cout << "No, element does not exist" << endl;    return  0;}


原创粉丝点击