Sunday, 6 November 2016

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.

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

1. Compilation With Custom Input

Hacker Rank solution for Sets-STL In C++

2.All Testcase's 

Hacker Rank solution for Sets-STL In C++


You May Like This:-

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment