Sort by

recency

|

795 Discussions

|

  • + 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!");
            }    
        }
    }
    
  • + 0 comments
    import java.io.*;
    import java.util.*;
    import java.util.stream.Collectors;
    
    class Output {
        public void getNum(List<List<Integer>> D,List<List<Integer>> X){
            for (List<Integer> sublist : X) {
                int y = sublist.get(0) - 1;
                int x = sublist.get(1) - 1;
                try {System.out.println(D.get(y).get(x));}
                catch (IndexOutOfBoundsException e) {System.out.println("ERROR!");}
            }
        }
    };
    
    public class Solution {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            List<List<Integer>> D = new ArrayList<>();
            List<List<Integer>> X = new ArrayList<>();
            int N = sc.nextInt();sc.nextLine();
            for (int i = 0; i < N; i++) 
                {D.add(Arrays.stream(sc.nextLine().trim().split("\\s+")).skip(1)
                .map(Integer::parseInt).collect(Collectors.toList()));}
            int Q = sc.nextInt();sc.nextLine();
            for (int i = 0; i < Q; i++) 
                {X.add(Arrays.stream(sc.nextLine().trim().split("\\s+"))
                .map(Integer::parseInt).collect(Collectors.toList()));}
            Output output = new Output();
            output.getNum(D,X);
            
        }
    }