-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwoDimensional_ArrayList
More file actions
68 lines (56 loc) · 1.48 KB
/
twoDimensional_ArrayList
File metadata and controls
68 lines (56 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/************
The first line has an integer N.
In each of the next N lines there will be an integer D denoting number of integers
on that line and then there will be D space-separated integers.
In the next line there will be an integer Q denoting number of queries.
Each query will consist of two integers X and Y.
In each line, output the number located in Yth position of Xth line.
If there is no such position, just print "ERROR!"
Sample Input
5
5 41 77 74 22 44
1 12
4 37 34 36 52
0
3 20 22 33
5
1 3
3 4
3 1
4 3
5 5
Sample Output
74
52
37
ERROR!
ERROR!
****************/
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<ArrayList<Integer>> rows = new ArrayList<>();
int n = sc.nextInt();
for (int i=0; i<n; i++) {
ArrayList<Integer> row = new ArrayList<>();
int d = sc.nextInt();
for (int j=0; j<d; j++) {
row.add(sc.nextInt());
}
rows.add(row);
}
int q = sc.nextInt();
for (int i=0; i<q; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
try {
System.out.println(rows.get(x-1).get(y-1));
}
//catch (IndexOutOfBoundsException e) {
catch (Exception e) {
System.out.println("ERROR!");
}
}
}
}