Variable Sized Arrays | HackerRank
Variable Sized Arrays | HackerRank
Find the element described in the query for integer sequences.
www.hackerrank.com
Goal
Create N number of variable-length arrays and find a element from quaries
Solution
If you know vector in C++, it would be easy problem.
you initialize vector of vector a and insert variable sized vector into a.
# Variable Sized Arrays
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n = 0;
int q = 0;
cin >> n >> q;
vector<vector<int>> a;
for(int i = 0 ; i < n ; i++){
int k = 0;
cin >> k;
vector<int> v;
int value = 0;
int index = 1;
while(cin >> value){
v.push_back(value);
index++;
if (index > k){
break;
}
}
a.push_back(v);
}
for(int i = 0; i < q ; i++){
int index, j ;
cin >> index >> j;
cout << a[index][j] << endl;
}
return 0;
}
'software Engineering > (C++)HackerRank' 카테고리의 다른 글
[C++] HackerRank - Arrays Introduction (0) | 2023.02.09 |
---|---|
[C++] HackerRank - Pointer (0) | 2023.02.08 |
[C++] HackerRank - Functions (0) | 2023.02.04 |
[C++] HackerRank - For Loop (0) | 2023.01.24 |
[C++] HackerRank - Conditional Statements (0) | 2023.01.24 |