There is a set of integers (repeating elements are allowed), which is initially empty. We define the following operations:
add x adds x to the set
del x deletes all elements in the set equal to x ask x to inquire about the element x in the set
For each operation, we require the following output.
After collection add output operation x number of
set before the output operation del x number
ask to output 0 or 1 indicates x ever been added to the collection ( 0 indicates never added), and then outputs the current set of x number, Use a space in the middle.
Input format
The first line is an integer n, indicating the number of commands. 0 ≤ n ≤ 1 0 0 0 0 0. The following n n lines of commands are described in Description.
Output format
There are n lines in total , and each line is output as required.
Sample input
7 add 1 add 1 ask 1 ask 2 del 2 del 1 ask 1
Sample output
1 2 1 2 0 0 0 2 1 0
#include<iostream> #include<set> #include<iterator> using namespace std; int main() { int n; cin>>n; char command[4]; multiset<int>mset; set<int>mm; multiset<int>::iterator it; int num; for (int i = 0; i < n; i++) { cin>>command>>num; switch (command[1]) { case 'd': mset.insert(num); mm.insert(num); cout<<mset.count(num)<<endl; break; case 'e': cout<<mset.count(num)<<endl; mset.erase(num); break; case 's': //find(key);//Find if the key key exists, if it exists, return the iterator of the element of the key; if not, return set.end (); if (mm.find (num) == mm.end ()) { cout << " 0 0 " << endl; } else { cout << " 1 " << mset.count (num) << endl; } break ; default : break ; } } }