I want to insert multiple array using Vector of vector.
For that I/P is like this:
2 : Number of array ( can be vary )
3 1 2 3 : 3( size of array) 1 2 3( elements in array )
4 4 5 6 7 : 4( size of array) 4 5 6 7 ( elements in array)
Then I need to perform some operation on it.
All the I/P is entered by user. Only its range is given.
2 <= No of array <= 10
1 <= Elements in array <= 1000000
For above I tried following ways :
int main()
{
int no_of_array, size;
long int num;
int j = 0;
cin >> no_of_array;
1st way :
vector < vector<int> > array_vector[no_of_array];
while( no_of_array -- )
{
cin >>size;
for( int i = 0; i < size ; i++ )
{
cin >> num;
array_vector[j].push_back({num});
}
j++;
}
cout<< vector_array[1][2]; // Error
2nd way :
vector< vector<int> > array_vector;
while( no_of_array --)
{
cin >> size;
for( int i = 0 ; i < size ; i++ )
{
cin >> num;
array_vector[j].push_back(num);
}
j++;
}
cout<< vector_array[1][2]; // Error
3rd way : ( Working )
vector<vector<int> > array_vector;
for( int i = 0 ; i < no_of_array ; i++ )
{
cin >> size;
vector<int> v;
for( int j = 0 ; j < size ; j++ )
{
cin >> num;
v.push_back(num);
}
array_vector.push_back(v);
}
cout<<array_vector[1][2]; // No Error
Somewhere I read 3rd way of vector of vector is not suitable for competitive programming. Why ??
What mistake I did while traversing the elements with 1st two approach ??