In: Computer Science
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
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] << " ";
}
}