-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvarszarrays.cpp
44 lines (37 loc) · 1.06 KB
/
varszarrays.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
#include <iostream>
#include <memory>
#include <vector>
int main() {
// std::vector<std::vector<int>*> vptr;
// Use smart pointers:
std::vector<std::unique_ptr<std::vector<int>>> vptr;
int input;
int arrays, queries;
int cursize;
int outerv, innerv;
// Read in number of arrays and number of queries:
std::cin >> arrays >> queries;
// Iterate over array info, populate arrays:
for (int i = 0; i < arrays; ++i) {
// vptr.push_back(new std::vector<int>);
// Use smart pointers:
vptr.push_back(std::unique_ptr<std::vector<int>>(new std::vector<int>));
std::cin >> cursize;
for (int j = 0; j < cursize; ++j) {
std::cin >> input;
vptr[i]->push_back(input);
}
}
// Iterate over query info and process:
for (int i = 0; i < queries; ++i) {
std::cin >> outerv >> innerv;
std::cout << vptr[outerv]->at(innerv) << '\n';
}
// Cleanup:
// Obviated with smart pointers:
/*
for (auto i: vptr)
delete i;
*/
return 0;
}