Sort by

recency

|

822 Discussions

|

  • + 0 comments
    class Solution {
        public static void main(String[] args) {
            Scanner scn = new Scanner(System.in);
            int length = scn.nextInt();
            ArrayList<Integer>[] lista = new ArrayList[length + 1];
            int a = 1;
            while (a <= length) {
                lista[a] = new ArrayList<>();
                lista[a].add(scn.nextInt()) ;
                for (int j = 1; j < lista[a].get(0) + 1 ; ++j) {
                    lista[a].add(scn.nextInt());
                }
                ++a;
            }
            int queries = scn.nextInt();
            while (queries > 0) {
                int x = scn.nextInt();
                int z = scn.nextInt();
                if (z <= lista[x].get(0)) {
                    System.out.println(lista[x].get(z));
                } else if (z > lista[x].get(0) || lista[x] == null){
                     System.out.println("ERROR!");
                }
                --queries;
            }
        }
    }
    
  • + 0 comments
    `
    public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            ArrayList<ArrayList<Integer>> al=new ArrayList<>();
            int n=sc.nextInt();
            for(int i=0;i<n;i++){
                int q=sc.nextInt();
                ArrayList<Integer> temp=new ArrayList<>();
                int x=0;
                while(x<q){
                    temp.add(sc.nextInt());
                    x++;
                }
                al.add(temp);
            }
            int q=sc.nextInt();
            for(int i=0;i<q;i++){
                int r=sc.nextInt();
                int c=sc.nextInt();
                try{
                    int ele=al.get(r-1).get(c-1);
                    System.out.println(ele);
                }
                catch(Exception e){
                    System.out.println("ERROR!");
                }
            }
        }
    

    `

  • + 0 comments
        public static void main(String[] args) {
    
            Scanner scanner = new Scanner(System.in);
            Integer n = scanner.nextInt();
            Integer[][] map = new Integer[n][];
    
            // Populate the Map
            for(int i = 0; i < n; i++){
                Integer firstDigit = scanner.nextInt();
                if(firstDigit > 0){
                    map[i] = new Integer[firstDigit]; 
                    for(int j = 0; j < map[i].length; j++){
                        map[i][j] = scanner.nextInt();
                    }
                } else {
                    map[i] = new Integer[]{};
                }
            }
    
            // Answer Queries
            Integer queries = scanner.nextInt();
            for(int k = 0; k < queries; k++){
                Integer y = scanner.nextInt() - 1;
                Integer x = scanner.nextInt() - 1;
                if(
                    y < 0 || x < 0 || 
                    y > map.length -1 || x > map[y].length -1
                ){
                    System.out.println("ERROR!");
                } else {
                    System.out.println(map[y][x]);
                }
            }
        }
    }
    
  • + 0 comments

    import java.util.*;

    public class HR082502 {

    public static void main (String[] args){
        try(Scanner sc = new Scanner(System.in)){
            //it is n lines
            int n = sc.nextInt();// 
            ArrayList<ArrayList<Integer>> arr = new ArrayList<>();
    
           for(int i=0; i <n; i++){
            int d = sc.nextInt();
            ArrayList<Integer> midArr = new ArrayList<>();
                for(int j =0; j<d;j++){
                    midArr.add(sc.nextInt());
                }
            arr.add(midArr);
           }
           //q queries
           int q = sc.nextInt(); 
           ArrayList<ArrayList<Integer>> que = new ArrayList<>();
    
           for(int i=0; i <q; i++){          
            ArrayList<Integer> midQue = new ArrayList<>();
                for(int j =0; j<2;j++){
                    midQue.add(sc.nextInt());
                }
            que.add(midQue);
           }
    
           //get x,y and check the existence 
           for(int i=0; i <q; i++){      
    
                int x = que.get(i).get(0) -1;
                int y = que.get(i).get(1)-1;                
                        if (x >= 0 && x < arr.size() && y >= 0 && y < arr.get(x).size()) {                        
                                System.out.println( arr.get(x).get(y));
                        } else {
                                System.out.println("ERROR!");                 
    
                        }
            }
        }
    }
    

    }

  • + 0 comments

    import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int d = sc.nextInt(); ArrayList row = new ArrayList<>(); for (int j = 0; j < d; j++) { row.add(sc.nextInt()); } list.add(row); } int q = sc.nextInt(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if (x <= list.size() && y <= list.get(x - 1).size()) { System.out.println(list.get(x - 1).get(y - 1)); } else { System.out.println("ERROR!"); } } } }