標題:
unordered_set 練習
[打印本頁]
作者:
tonyh
時間:
2023-8-31 20:44
標題:
unordered_set 練習
#include<bits/stdc++.h>
using namespace std;
//unordered_set<int> us; //1
//unordered_set<int> us={1,1,2,3,5,3,4}; //2
/*int arr[8]={1,1,2,3,5,3,4,7}; //3
unordered_set<int> us(arr, arr+8);*/
vector<int> v={1,1,2,3,5,3,4,7}; //4
unordered_set<int> us(v.begin(), v.end());
int main()
{
cin.tie(0);
cin.sync_with_stdio(0);
/*
us.insert(1);
us.insert(2);
us.insert(7);
us.insert(5);
us.insert(2);
us.insert(1);
*/
for(int i: us)
cout<<i<<endl;
cout<<"----------"<<endl;
cout<<us.size()<<endl;
cout<<us.count(2)<<endl;
cout<<us.count(8)<<endl;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2