Created
November 20, 2020 08:59
-
-
Save omi-akif/7621b21d1bbbdb4c73aa02ad1ac62a79 to your computer and use it in GitHub Desktop.
A cpp program to create variable arrays and query them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
/* | |
1. Compile the program with using g++ compiler -> variable_array.cpp -o variable | |
2. Run the compiled file in Terminal(Ubuntu) or Command Promt(Windows) | |
3. First Line/Step -> Enter the number of variable length arrays and the number of queries. | |
Second Line/Step -> Enter the number of data entries within the variable sized arrays and then enter the numberes. | |
Third Line/Step -> Enter the index of variable array and the index of the array within the array. | |
Example: | |
Input: | |
2 2 | |
2 1 3 | |
3 1 4 5 | |
0 1 | |
1 0 | |
Output: | |
3 | |
1 | |
*/ | |
using namespace std; | |
int main(){ | |
int n, q; // Entries for number of variable length of arrays and the number of queries respectively | |
int k; | |
int i, j; | |
cin >> n; //enter number of variable-length arrays | |
cin >> q; //enter the number of queries | |
//Created my first two dimensional array | |
int **a = new int *[n]; //point to an array of arrays | |
for(int x = 0; x < n; x++){ // Initialize 'x' for x is the numer of entries for a[] | |
cin >> k; // Enter the number of entries | |
a[x] = new int [k]; | |
for(int l = 0; l < k; l++){ //Iniatialize 'l' for l is the number of a[x] | |
cin >> a[x][l]; | |
} | |
} | |
int *temp = new int [q]; //temporary array | |
for(int x = 0; x < q; x++){ // Inserting number of queries | |
cin >> i; | |
cin >> j; | |
temp[x] = a[i][j]; | |
} | |
for(int x = 0; x < q; x++){ | |
cout << temp[x] << endl; //Outputting number of queries. | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment