Sort by

recency

|

796 Discussions

|

  • + 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!");
            }    
    }
    
  • + 0 comments
    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!");
                }
            }
        }
    }
    
  • + 0 comments

    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 sc = new Scanner(System.in);
        ArrayList<ArrayList<Integer>> arr = new ArrayList<ArrayList<Integer>>();
    
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int d = sc.nextInt();
            arr.add(new ArrayList<Integer>());
            for (int j = 0; j < d; j++) {
                arr.get(i).add(sc.nextInt());    
            }
        }
    
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            int y = sc.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!");
            }    
        }
    }