You are viewing a single comment's thread. Return to all comments →
using namespace std;
void setSize(int& s){cin >> s;} void setQuery(int& q){ cin >> q;} vector stringParser(const std::string& str) { std::stringstream ss(str); vector list; string tempstr; ss.clear(); while(std::getline(ss,tempstr,' ')){ std::stringstream temp(tempstr); int n=-1; if(temp>>n) list.push_back(n); } return list; } std::vector> populateJaggedArray(const int sizeJagged){ std::vector> jaggedArray(sizeJagged); cin.ignore(); for (int i = 0; i < sizeJagged; i++) { std::string str; std::getline(cin, str); vector input = stringParser(str); for (int j = 0; j < input[0]; j++) jaggedArray[i].push_back(input[j + 1]); } return jaggedArray; } vector getQuery(int query, vector>& arr) { vector result; int x=-1,y=-1; for (int i = 0; i < query; i++){ cin>>x>>y; result.push_back(arr[x][y]); } return result; } void printQuery(vector& result) { for (int i = 0; i < result.size(); i++) cout<> jaggedArray=populateJaggedArray(sizeJagged); vector result=getQuery(query,jaggedArray); printQuery(result);
return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
include
include
include
using namespace std;
void setSize(int& s){cin >> s;} void setQuery(int& q){ cin >> q;} vector stringParser(const std::string& str) { std::stringstream ss(str); vector list; string tempstr; ss.clear(); while(std::getline(ss,tempstr,' ')){ std::stringstream temp(tempstr); int n=-1; if(temp>>n) list.push_back(n); } return list; } std::vector> populateJaggedArray(const int sizeJagged){ std::vector> jaggedArray(sizeJagged); cin.ignore(); for (int i = 0; i < sizeJagged; i++) { std::string str; std::getline(cin, str); vector input = stringParser(str); for (int j = 0; j < input[0]; j++) jaggedArray[i].push_back(input[j + 1]); } return jaggedArray; } vector getQuery(int query, vector>& arr) { vector result; int x=-1,y=-1; for (int i = 0; i < query; i++){ cin>>x>>y; result.push_back(arr[x][y]); } return result; } void printQuery(vector& result) { for (int i = 0; i < result.size(); i++) cout<> jaggedArray=populateJaggedArray(sizeJagged); vector result=getQuery(query,jaggedArray); printQuery(result);
}