Set is used when you write a question word to search for it. In the evening, codeforces #497 div2 D is used for map.
I think the functions of set and map are quite similar. Here is a summary;
Here we will not specifically compare the similarities and differences, so as not to look messy. Here we will explain them separately;
Set:
# Include <set>
Set <...> S; (the type can be int, Char, string)
Functions:
Insert element; S. insert ()
Search element; S. Find ()
Delete element; S. Erase ()
Extract the beginning and end elements; set <int>: iterator itor; // This sentence must be written! Note!
Itor = S. Begin (); itor = S. End ();
Itor! = S. End (); can be used to determine whether an element is found
Set itself can define sorting;
Set <int, greater <int> S;
Set <int, less <int> S;
Insert or delete a single element, a range, or all, which can be customized;
I feel that a great god's blog is very detailed and I have learned it;
Map
Definition # include <map>
Map <...,...> F;
It can be int, Char, string
Because map is similar to hash, elements in map correspond to projection;
Here is an example: (See here)
When you need to store data in an integer array,
Ai-> I;
Map <int, int> B;
Simple write, which can be B [A [I] = I;
That is to say, the subscript in B [] and its corresponding value are both int;
Char also means the same
When you need to store B ['abc'] = 'defg';, you need to use Map <char, char> B;
Similar to set, map can insert elements, search for elements, and delete elements.
Insert can be simply written as B [A [I] =...
Search and delete are the same as set
The difference between map and set is better. Because map is closer to hash, the speed is much faster than set, but the set function is more complete than map.
Map, set template [STL]