Skip to content

Instantly share code, notes, and snippets.

@imoasislee
Created February 28, 2022 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imoasislee/2b9916bac92ce744b41a37419c918008 to your computer and use it in GitHub Desktop.
Save imoasislee/2b9916bac92ce744b41a37419c918008 to your computer and use it in GitHub Desktop.
// set
#include <iostream>
#include <cstring>
#include <set> // 使用multiset和set
using namespace std;
int main()
{
set<int> st;
int a[10] = {1,3,9,2,87,12,91,55,90,90}; // 包含重复元素90
for (int i=0; i<10; ++i)
{
st.insert(a[i]);
}
cout << st.size() << endl; // size=9
set<int>::iterator i;
for(i=st.begin(); i!=st.end(); ++i)
{
cout << *i << ","; // 逐项输出
}
cout << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment