# Hacker Rank solution for Sets-STL In C++

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++.

Check This- Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.

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.

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:-

1. Compilation With Custom Input

2.All Testcase's

You May Like This:-
Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.