Question

In: Computer Science

IN C++: Create sets of 1 Million integers with the following characteristics; Sets where no numbers...

IN C++:

Create sets of 1 Million integers with the following characteristics;
Sets where no numbers repeat
Sets where the range of numbers is 1% of the array size
Sets where no numbers repeat and each integer has 20 digits

Solutions

Expert Solution

Here is the code. Run this in terminal using g++ command to see output.

Properties of output: The following code prints all the integers from 10000000000000000001 (20 digits) to 10000000000001000000 (20 digits).

All the digits has been stored in a vector (dynamic array) of length 100000000.

Hence, all the required properties are satisfied:

1. It has all unique elements.

2. The range is 1% of the size of the array in which it is stored (here 10000000000000000001 to 10000000000001000000 are stored, which are 1,000,000 unique integers, in an array of length 1,000,000,00).

3. All integers are of 20 digit's length.

#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

vector<string> v;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);

string s = "10000000000000000000";
string s1, s3;
ll x, y;
for (ll i = 1; i <= 1000000; i++) {
    s1 = to_string(i);
    string s2;
    x = s.size();
    y = s1.size();
    for (ll j = 0; j < x - y; j++) {
      s2 += s[j];
    }
    s3 = s2 + s1;
    v.push_back(s3);
}
for (ll i = 0; i < 1000000; i++) {
    cout << v[i] << " ";
}
}


Related Solutions

IN C++: Create sets of 1 Million integer, where no integer is repeated. Insert these numbers...
IN C++: Create sets of 1 Million integer, where no integer is repeated. Insert these numbers to an AVL tree and an R-B tree. Using a random number generator, select 10% of the numbers in the trees and delete them. Repeat the experiment 10 times. Report your answers in a tables
C++ Create a program which randomly generates 3 sets of x and y Integers and one...
C++ Create a program which randomly generates 3 sets of x and y Integers and one randomly generated Integer. Two of the sets of Integers will represent the end points of a line segment. The other set of Integers and the other Integer will represent the midpoint of a circle and its radius. The coordinates should be randomly generated using a user defined function that returns an Integer value based on from and to parameters; see the function declaration in...
write C program to create 4 threads for summing the numbers between 1 and 40 where...
write C program to create 4 threads for summing the numbers between 1 and 40 where the first thread computes the sum between 1 and 10; the second thread computes the sum between 11 and 20; the third thread computes the sum between 21 and 30; and the fourth thread compute the sum between 31 and 40. The output should be similar to the following. The sum from 1 to 10 = 55 The sum from 11 to 20 =...
Make up three different data sets with 5 numbers each that have the following characteristics; the...
Make up three different data sets with 5 numbers each that have the following characteristics; the word "set" means there will be 2 lists of 5 numbers in each set. List the numbers in each dataset. For example in part a) you will have a list of 5 numbers with a mean of X, and the second list of 5 numbers will have the same mean. However, the two lists of 5 numbers need to have different standard deviations. That...
Which of the following sets of quantum numbers are not allowed? For the sets that are...
Which of the following sets of quantum numbers are not allowed? For the sets that are incorrect state what is wrong. For the sets that are correct, give the orbital designation (eg 1s, 2px). n l ml ms a) 2 1 +1 +1/2 b) 2 2 -1 -1/2 c)75-4 0 d) 4 2 -2 +1/2
Create a c++ program to compute the product of two integers. call create the following functions:...
Create a c++ program to compute the product of two integers. call create the following functions: 1. getNum - to accept only positive numbers && will call computeProd. 2.computeProd - to compute the product of the numbers & will call the function displayProduct. 3. displayProduct - to display the product. Call the function getNum in the main function. Compute the product w/o using the multiplication operator(*). using #include <iostream> only
I have to create a program in C++ where a user can enter as many numbers...
I have to create a program in C++ where a user can enter as many numbers as they want (they predetermine the number of values to be inputted) and then the program can echo that input back to the user and then determine if the numbers were even, odd, or a zero and it outputs how many of each were found. This is to be down with four void functions and no arrays. The program initializes the variables zero, odds,...
Using c++, 1: Create a vector of 20 randomly generated integers, then 2. Create a new...
Using c++, 1: Create a vector of 20 randomly generated integers, then 2. Create a new vector that will only store the even numbers from the original vector. 3. Display the original vector and the vector of even integers to the console.
Using C++, find the sum of the squares of the integers from 1 to MySquare, where...
Using C++, find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the user enters a positive integer.
Write a program where you- 1. Create a class to implement "Double Linked List" of integers....
Write a program where you- 1. Create a class to implement "Double Linked List" of integers. (10) 2. Create the list and print the list in forward and reverse directions. (10)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT