-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJava Arraylist
54 lines (46 loc) · 1.05 KB
/
Java Arraylist
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
/*Output Format
In each line, output the number located in position of 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! */
code
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.nextLine();
ArrayList<ArrayList<String>> a = new ArrayList<ArrayList<String>>(n);
for (int i = 0; i < n; i++) {
s = sc.nextLine();
a.add(i, new ArrayList<String>(Arrays.asList(s.split("\\s"))));
}
int m = sc.nextInt();
for (int i = 0; i < m; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
if (x <= a.size() && y < a.get(x-1).size() && y >= 0) {
System.out.println(a.get(x-1).get(y));
} else {
System.out.println("ERROR!");
}
}
}
}