1#include <cstdio>2#include <iostream>3#include <cstdlib>4#include <cmath>5#include <vector>6#include <algorithm>7#include <cstring>8#include <vector>9#include <map>Ten#include <stack> One#include <Set> A #defineMAXN +50 - #defineINF 0x7fffffff - #defineXiao 1e-9 the using namespacestd; - Set<int>:: iterator iter; - intMain () - { + inta[]={1,2,3}; - Set<int>s; +S.insert (a,a+3);//with set<int> s (a,a+3); equivalent A //S.find () finds if there is a number in the set, and ITER is its location, and if so, returns to ITER, without returning s.end (); at { - - if((Iter=s.find (3))!=s.end ()) - { -cout<<*iter<<Endl; - } in } - //Insert (First,second) Inserts the value between the locator first and second into the set, and the return value is null to { + for(Iter=s.begin (); Iter!=s.end (); ++iter) cout<<*iter<<" "; -cout<<Endl; the } * //The Insert (key_value) return value is Pair<set<int>::iterator,bool>,bool whether the insert succeeds, iterator represents the insertion position, and if Key_ Value is already in set, then iterator returns where $ {Panax Notoginsengpair<Set<int>::iterator,BOOL>PR; -Pr=s.insert (5); the if(Pr.second) cout<<*pr.first<<Endl; + } A //Lower_bound (Key_value) returns the first position of a value greater than or equal to Key_value the //Upper_bound (Key_value) returns the position of the last value greater than or equal to Key_value + { -Cout<<*s.lower_bound (2) <<Endl; $Cout<<*s.upper_bound (2) <<Endl; $ } - return 0; -}
Set is really a magical thing ~~~~~
Set Basic Usage-----2