forked from Sam071100/CodeForces-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorsOFVectors.cpp
More file actions
71 lines (61 loc) · 1.43 KB
/
VectorsOFVectors.cpp
File metadata and controls
71 lines (61 loc) · 1.43 KB
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
/*
C++ program to create a 2D vector where
every row has a certain number of values
as defined by the user.(On line 13)
*/
#include <iostream>
#include <vector>
using namespace std;
int main()
{
/* Here we tell how many rows
the 2D vector is going to have. */
int row = 5;
/* We define the number of values
each row is supposed to have. */
int colom[] = {5, 3, 4, 2, 1};
/*
We now create a vector of vector with size
equal to row.
*/
vector<vector<int>> vec(row);
/*
On line 21 we created a 2D vector and assinged
it a capacity of "row"(in this case 5) units.
*/
/*
Now we will proceed to create the sturture of
our 2D vector by assigning the value of rows and
columns through a nested for loop.
*/
for(int i = 0; i < row; i++)
{
/* Declaring the size of the column. */
int col = colom[i];
/*
On the 43rd line we declare the
i-th row to the size of the column.
We create a normal vector of capacity "col" which
in every iteration of the for loop will define the
values inside of each row.
*/
vec[i] = vector<int>(col);
for(int j = 0; j < col; j++)
{
vec[i][j] = j + 1;
}
}
/*
We now finally use a simple nested for loop
to print the 2D vector that we just created above.
*/
for(int i = 0; i < row; i++)
{
for (int j = 0; j < vec[i].size(); j++)
{
cout << vec[i][j] << " ";
}
cout << endl;
}
return 0;
}