Sort by

recency

|

798 Discussions

|

  • + 0 comments
    import java.util.List;
    import java.util.Scanner;
    import java.util.stream.Stream;
    
    import static java.util.stream.Collectors.toList;
    
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int numberOfArrays = getInputNumber(scanner);
            int numberOfQuerys = 0;
            List<List<Integer>> arraysOfNumbers = new ArrayList<>();
            List<List<Integer>> arrayOfQuery = new ArrayList<>();// x , y in every query
    
            for (int i = 0; i < numberOfArrays; i++) {
                List<Integer> list = getInputListNumbers(scanner);
                list.remove(0);
                arraysOfNumbers.add(list);
            }
    
            numberOfQuerys = getInputNumber(scanner);
            while (numberOfQuerys-- > 0) {
                arrayOfQuery.add(getInputListNumbers(scanner));
            }
            scanner.close();
    
            arrayOfQuery.forEach(list -> {
                int x = list.get(0); // position in array of numbers
                int y = list.get(1);// position in array
                printNumber(x, numberOfArrays, arraysOfNumbers, y);
            });
        }
    
        private static void printNumber(int x, int numberOfArrays, List<List<Integer>> arraysOfNumbers, int y) {
            if(x <0 || x > numberOfArrays){
                System.out.println("ERROR!");
            }
            List<Integer> array = arraysOfNumbers.get(x -1);
            try{
                System.out.println(array.get(y -1));
            }catch (Exception e){
                System.out.println("ERROR!");
            }
        }
    
        private static int getInputNumber(Scanner scanner) {
            return Integer.parseInt(scanner.nextLine());
        }
    
        private static List<Integer> getInputListNumbers(Scanner scanner) {
            return Stream.of(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(toList());
        }
    }
    
  • + 0 comments

    Scanner sc = new Scanner(System.in); int p = sc.nextInt(); List> lisOfLis = new ArrayList<>(); for(int i=0;i list1 = new ArrayList<>();
    for(int j=0;j= 0 && x < p && y >= 0 && y < lisOfLis.get(x).size()){ List newlist = lisOfLis.get(x); System.out.println(newlist.get(y)); }else{ System.out.println("ERROR!"); }
    }
    sc.close();

  • + 0 comments

    my code:

    import java.util.ArrayList; import java.util.Scanner;

    public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in);

        ArrayList<ArrayList<Integer>> ml = new ArrayList<>();
    
        int n = scan.nextInt();      
        for (int i = 0; i < n; i++) {
            int x = scan.nextInt();
            ArrayList<Integer> list = new ArrayList<>();
            for (int j = 0; j < x; j++) {
                int z = scan.nextInt();
                list.add(z);
            }
            ml.add(list);
        }
    
        int m = scan.nextInt();
        for(int i=0; i<m; i++){
            int a= scan.nextInt();
            int b= scan.nextInt();
            try{
                System.out.println(ml.get(a-1).get(b-1));
            }
            catch(IndexOutOfBoundsException e){
                System.out.println("ERROR!");
            }
        }
    
        scan.close();
    }
    

    }

  • + 0 comments
            ****Scanner sc =new Scanner(System.in);
            ArrayList<ArrayList<Integer>>arr= new ArrayList<ArrayList<Integer>>();
            
            int n= sc.nextInt();
            for(int i=0; i<n; i++){
                arr.add(new ArrayList<Integer>());
                int d= sc.nextInt();
                for(int j=0; j<d; j++){
                    arr.get(i).add(sc.nextInt());
                    }
            }
            int q= sc.nextInt();
            for(int k=0; k<q; k++){
                int x=sc.nextInt();
                int y=sc.nextInt();
                try{
                    System.out.println(arr.get(x-1).get(y-1));
                }catch(Exception e){
                    System.out.println("ERROR!");
                }
            }
            
    
  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>(n);
    
            for(int i=0;i<n;i++){            
                    int d = in.nextInt();
                    arr.add(new ArrayList<Integer>());
                    for(int j=0;j<d;j++){
                            arr.get(i).add(in.nextInt());
                    }
            }
    
            int q = in.nextInt();
    
            for (int i = 0; i < q; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            try{    
                    if (arr.get(x - 1).get(y - 1) != null) {
                            System.out.println(arr.get(x - 1).get(y - 1));
    
                    } else {
                            System.out.println("ERROR!");
                    }
            }    
            catch(Exception e){
            System.out.println("ERROR!");
            }    
    }