Maximum of All Subarrays of Size K Using Set in C++ STL

Ayush Gupta
Updated on 06-Apr-2020 14:16:34

230 Views

In this tutorial, we will be discussing a program to get maximum of all subarrays of size k using set in C++ STL.For this we will be provided with a array of size N and integer K. Our task is to get the maximum element in each K elements, add them up and print it out.Example Live Demo#include using namespace std; //returning sum of maximum elements int maxOfSubarrays(int arr[], int n, int k){    set q;    set::reverse_iterator it;    //inserting elements    for (int i = 0; i < k; i++) {       q.insert(pair(arr[i], i));    } ... Read More

Menu Driven C++ Program for a Simple Calculator

Ayush Gupta
Updated on 06-Apr-2020 14:15:19

1K+ Views

In this tutorial, we will be discussing a program to create a menu driven program for a simple calculator.This program will give user the ability to choose among the following mathematical operations − addition, subtraction, multiplication, division, HCF and LCM.Example Live Demo#include using namespace std; //displaying the menu void menu(){    cout

Multiset in C++ Standard Template Library (STL)

Ayush Gupta
Updated on 06-Apr-2020 14:10:13

210 Views

In this tutorial, we will be discussing a program to understand Multiset in C++ STL (Standard Template Library).Multiset are associative containers much similar to sets. The one difference multiset holds is they can even contain duplicate values.Example Live Demo#include #include #include using namespace std; int main(){    multiset gquiz1;    //inserting values    gquiz1.insert(40);    gquiz1.insert(30);    gquiz1.insert(60);    gquiz1.insert(20);    gquiz1.insert(50);    gquiz1.insert(50);    gquiz1.insert(10);    multiset :: iterator itr;    cout

Perform Simple Validation in MongoDB

AmitDiwan
Updated on 06-Apr-2020 14:09:04

270 Views

For validation in MongoDB, use validator. Following is the query to create validation on collection in MongoDB −> db.createCollection( "demo437" , { ...    validator: { $jsonSchema: { ...       bsonType: "object", ...       required: [ "FirstName", "LastName"], ...       properties: { ...          FirstName: { ...             bsonType: "string", ...             description: "This is required" }, ...             LastName: { ...                bsonType: "string", ...         ... Read More

Multiset Lower Bound in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:05:36

349 Views

In this tutorial, we will be discussing a program to understand multiset lower_bound() in C++ STL.The function lower_bound() returns the first existence of the element in the container equivalent to the provided parameter, else it returns the element immediately bigger than that.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(2);    s.insert(2);    s.insert(1);    s.insert(4);    cout

Multiset Upper Bound in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 14:00:38

341 Views

In this tutorial, we will be discussing a program to understand multiset upper_bound() in C++ STL.The function upper_bound() returns the pointer to an element which is bigger than the one provided as a parameter, else it returns the pointer to the last element in the container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(1);    s.insert(3);    s.insert(3);    s.insert(5);    s.insert(4);    cout

Fetch Specific Record Using MySQL Query with AND and OR Operator

AmitDiwan
Updated on 06-Apr-2020 14:00:14

138 Views

Let us first create a table −mysql> create table DemoTable2015    -> (    -> StudentId int,    -> StudentName varchar(20),    -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (1.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2015 values(1, 'Chris', 'US'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2015 values(2, 'Bob', 'UK'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2015 values(3, 'David', 'AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2015 values(4, 'Robert', 'US'); Query OK, 1 ... Read More

Negative Binomial Distribution in C++ with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:58:33

186 Views

In this tutorial, we will be discussing a program to understand negative_binomial_distribution in C++.This function follows the negative Binomial discrete distribution and produces integers according to this random distribution.Example Live Demo#include using namespace std; int main() {    //setting number of experiments    const int exps = 10000;    const int numberstars = 100;    default_random_engine generator;    negative_binomial_distribution distribution(4, 0.5);    int p[10] = {};    for (int i = 0; i < exps; ++i) {       int counting = distribution(generator);       if (counting < 10)          ++p[counting];    }    cout

Multiset Max Size in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:55:35

136 Views

In this tutorial, we will be discussing a program to understand multiset max_size() in C++ STL.The function max_size() returns the maximum number of elements a given container can hold.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    s.insert(13);    s.insert(25);    s.insert(24);    cout

Multiset Size in C++ STL with Examples

Ayush Gupta
Updated on 06-Apr-2020 13:53:28

121 Views

In this tutorial, we will be discussing a program to understand multiset size() in C++ STL.The function size() returns the number of elements present into a given container.Example Live Demo#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    cout

Advertisements