We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>//using namespace std;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn;//number of Arraysintq;//number of QueriesinttempValue;//would be used to store the input value of each element in inner vector//storing the number of arrays in 'n' and number of queries in 'q'std::cin>>n>>q;/////////////////////////*creation of vectors*/////////////////////////creating 'n' number of vector<int>std::vector<std::vector<int>>a(n);intnumberOfElements;//number of elements in each inner vector//for each vectorfor(inti=0;i<n;i++){//store the number of elements desiredstd::cin>>numberOfElements;//runs 'numberOfElements timesfor(intj=0;j<numberOfElements;j++){std::cin>>tempValue;a[i].push_back(tempValue);}}////////////////////////*queries of vectors*//////////////////////intoutVector;//stores the queried outer vector indexintinVector;//stores the queried inner vector index//runs 'q' timesfor(inti=0;i<q;i++){std::cin>>outVector>>inVector;std::cout<<a[outVector][inVector];std::cout<<std::endl;}return0;}
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
C++ vector solution for coding begginers: