Problem:- Sets-STL Inheritance Hacker Rank Solution or Sets-STL Inheritance hacker rank solution c++ orMulti Level Inheritance in java or Sets-STL Inheritance solution or Sets-STL Inheritance solution in C++ or Sets-STL Inheritance hacker rank solution in Java or Sets-STL Inheritance hacker rank solution c++ or Sets-STL Inheritance hacker rank solution c++ or Sets-STL Inheritance program in c or Sets-STL Inheritance solution in C or Hacker Rank Solution For Sets-STL Inheritance in C++ or Sets-STL Inheritance in C++ or Hacker Rank solution for Sets-STL Inheritance in C++.
Explanation:- In C++ Sets ( are containers that store unique elements ) is an Important part of the STL ( Standard Template Library). Mostly used member functions of sets are:
Declaration:
set<int>st; //Creates a set of integers.
//st is a name of set
Size:
int length=s.size(); //Gives the size of the set.
//length is a size of set
Insert:
s.insert(x); //Inserts an integer x into the set s.
Erasing an element:
s.erase(val); //Erases an integer val from the set s.
Submit your solution here:- Click here
Solution:-
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
set<int>s;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
s.insert(a);
}
cin>>n;
for(int i=0;i<n;i++)
{
int q,t;
cin>>t>>q;
switch(t)
{
case 1:
{
s.insert(q);
break;
}
case 2:
{
s.erase(q);
break;
}
case 3:
{
set<int>::iterator itr=s.find(q);
if(itr==s.end())
cout<<"No"<<endl;
else
cout<<"Yes"<<endl;
break;
}
}
}
return 0;
}
Output:-
2.All Testcase's
You May Like This:-
1. Hacker Rank Solution for 30 Days of Code
2. Hacker Rank solution for Attribute Parser
3. Java Program For Find The Gross Salary Of An Employee
4. C++ Program For School Management System ( SMS Project ) With Source Code
5. Hacker Rank Solution For Mini-Max Sum
6. Hacker Rank Solution Program In C++ For " Vector-Sort"
7. Hacker Rank Solution Program In C++ For " Vector-Erase "
8. Hacker Rank Solution Program In C++ For " Lower Bound-STL"
9. Hacker Rank Solution Program In C++ For " Maps-STL"
10. Hacker Rank Solution Program In C++ For " Print Pretty"
0 Comments: