Sort by

recency

|

825 Discussions

|

  • + 0 comments

    Scanner sc = new Scanner(System.in); int n = sc.nextInt();

        List<List<Integer>> lines = new ArrayList<>();
    
        for(int i = 0; i<n; i++)
        {
            int d = sc.nextInt();
            List<Integer> line = new ArrayList<>();
    
            for(int j=0; j<d; j++)
            {
                line.add(sc.nextInt());
            }
            lines.add(line);
        }
    
        int q = sc.nextInt();
    
        for(int i=0; i<q;i++)
        {
            int x = sc.nextInt();
            int y = sc.nextInt();
    
            try 
            {
                System.out.println(lines.get(x-1).get(y-1));
            }
            catch (IndexOutOfBoundsException e) 
            {
                System.out.println("ERROR!");
            }
         }
    
    }
    
  • + 0 comments
    Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            scan.nextLine();
            int ar[][] = new int[n][];
            for(int i=0;i<n;i++){
                String s[] = scan.nextLine().split(" ");
                ar[i] = new int[s.length]; 
                for(int j=0;j<ar[i].length;j++){
                    ar[i][j] = Integer.valueOf(s[j]);
                }
                // System.out.println(Arrays.toString(ar[i]));
            }
            int qSize = scan.nextInt();
            // System.out.println("Q "+qSize);
            for(int i=0;i<qSize;i++){
                int x= scan.nextInt();
                int y =scan.nextInt();
                try{
                    System.out.println(ar[x-1][y]);
                }catch(Exception e){
                    System.out.println("ERROR!");
                }
            }
            scan.close();
    
  • + 0 comments
            ArrayList <ArrayList> matrix = new ArrayList<>();
            Scanner s = new Scanner(System.in);
            
            int lineCount = s.nextInt();
            //System.out.println("LineCount= " + lineCount);
            
            s.nextLine();
            
            for(int i=0; i<lineCount; i++){
                ArrayList tmpAL = new ArrayList<>();
                String[] stmp = s.nextLine().trim().split(" ");
                
                for(int j=0; j<stmp.length; j++){
                   tmpAL.add(stmp[j]);
                   //System.out.println("stmp " + stmp[j]);
                }
                
                matrix.add(tmpAL);
            }
            
            int queryCount = s.nextInt();
            //System.out.println("QC: " + queryCount);
            
            for(int i=0; i<queryCount; i++){
                int x = s.nextInt();
                int y = s.nextInt();
              
                //System.out.println(matrix.get(x-1).get(y));
                
                try{
                    System.out.println(matrix.get(x-1).get(y));
                } catch(Exception ex){
                    System.out.println("ERROR!");
                }
            }
            
            s.close();
        }
    
  • + 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!");
                }
            }
        }
    

    `