Training/HackerRank

[C++][Introduction] Variable Sized Arrays

FATKITTY 2021. 8. 7. 12:30
반응형

https://www.hackerrank.com/challenges/variable-sized-arrays/problem

 

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
  int n, q, i, j, len;
  cin >> n >> q;
  vector<vector<int>> arr(n);

  for (int a = 0; a < n; a++) {
        cin >> len;
        arr[a].resize(len);
        // resize the container so that it contains n elements
        for (int b = 0; b < len; b++) {
            cin >> arr[a][b];
        }
    }

    for (int c = 0; c < q; c++) {
      cin >> i >> j;
      cout << arr[i][j] << endl;
    }

    return 0;
}

 

Testcase

Input

10 10
3 916135 272188 794963
3 178997 502468 671251
1 122266
3 223511 996043 990104
3 319694 335208 200789
2 867809 273793
1 925358
1 71140
1 862238
1 994309
6 0
5 0
5 0
7 0
5 0
6 0
3 2
3 1
0 0
9 0

 

Output
925358
867809
867809
71140
867809
925358
990104
996043
916135
994309

 

반응형

'Training > HackerRank' 카테고리의 다른 글

[C++][STL] Sets-STL  (0) 2021.08.17
[C++][STL] Lower Bound-STL  (0) 2021.08.08
[C++][STL] Vector-Erase  (0) 2021.08.07
[C++][Classes] Class  (0) 2021.08.07
[C++][Strings] StringStream  (0) 2021.08.04