Set Basic Usage-----2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.