-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path96_variablr_sized.cpp
76 lines (63 loc) · 1.61 KB
/
96_variablr_sized.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
int no_array;
int no_q;
cin>>no_array;
cin>>no_q;
int array_size;
int array[no_array][10000];
for (int i = 0; i < no_array; i++)
{
cin>>array_size;
for (int j = 0; j < array_size; j++)
{
cin>>array[i][j];
}
}
int array_2[no_q];
int array_3[no_q];
for (int k = 0;k<no_q;k++)
{
cin>>array_2[k];
cin>>array_3[k];
}
for(int b = 0;b<no_q;b++){
cout<<array[(array_2[b])][(array_3[b])]<<endl;
}
cout<<endl;
return 0;
}
// this is hackerank solution i have to try
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int n;
int q;
cin >> n >> q;
// Create an array of pointers to integer arrays
// (i.e., an array of variable-length arrays)
int** outer = new int*[n];
// Fill each index of 'outer' with a variable-length array
for(int i = 0; i < n; i++) {
int k;
cin >> k;
// Create an array of length 'k' at index 'i'
outer[i] = new int[k];
// Fill each cell in the 'inner' variable-length array
for(int j = 0; j < k; j++) {
cin >> outer[i][j];
}
}
// Perform queries:
while(q-- > 0) {
int outer_index;
int inner_index;
cin >> outer_index >> inner_index;
// Find the variable-length array located at outer_index
// and print the value of the element at inner_index.
cout << outer[outer_index][inner_index] << endl;
}
return 0;
}