Added 11 solutions

This commit is contained in:
rshaghoulian
2017-03-24 00:02:30 -05:00
parent 8239026cea
commit 5f4c2f4a78
26 changed files with 558 additions and 120 deletions
@@ -5,23 +5,20 @@
import java.util.Scanner;
import java.util.ArrayList;
/* We need a 2-D array to solve this problem. We can't use an int[][] since we
don't know the initial dimensions. So, we use ArrayList<ArrayList<Integer>> */
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
/* Save numbers in 2-D ArrayList */
ArrayList<ArrayList<Integer>> list = new ArrayList<>();
ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
for (int row = 0; row < n; row++) {
int d = scan.nextInt();
ArrayList<Integer> numbers = new ArrayList<>();
ArrayList<Integer> list = new ArrayList<>();
for (int col = 0; col < d; col++) {
numbers.add(scan.nextInt());
list.add(scan.nextInt());
}
list.add(numbers);
lists.add(list);
}
/* Answer the queries */
@@ -29,14 +26,14 @@ public class Solution {
for (int i = 0; i < q; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
try {
int num = list.get(x-1).get(y-1);
System.out.println(num);
} catch (IndexOutOfBoundsException e) {
ArrayList<Integer> list = lists.get(x-1);
if (y <= list.size()) {
System.out.println(list.get(y-1));
} else {
System.out.println("ERROR!");
}
}
scan.close();
scan.close();
}
}