X Tutup

Sort by

recency

|

828 Discussions

|

  • + 0 comments

    import java.util.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num1=in.nextInt();
        ArrayList<ArrayList<Integer>> matrix = new ArrayList<>();
        for(int i=0;i<num1;i++){
            int n=in.nextInt();
            ArrayList<Integer> row = new ArrayList<>();
            for(int j=0;j<n;j++){
                row.add(in.nextInt());
            }
            matrix.add(row);
        }
        int disp=in.nextInt();
        for(int i=0;i<disp;i++){
            int x=in.nextInt()-1;
            int y=in.nextInt()-1;
            if(x<matrix.size() && y< matrix.get(x).size()){
                System.out.println(matrix.get(x).get(y));
            }
            else{
                System.out.println("ERROR!");
            }
    
        }
        in.close();
    }
    

    }

  • + 0 comments
    import java.util.*;
    
    public class Solution {
    
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int counter = Integer.parseInt(scanner.nextLine());
            List<String[]> numbers = new ArrayList<>();
            for (int i = 0; i < counter; i++) {
                String row = scanner.nextLine(); 
                numbers.add(row.isBlank() ? new String[0] : row.split("\\s+"));
            }
            counter = Integer.parseInt(scanner.nextLine());
            for (int i = 0; i < counter; i++) {
                String[] tokens = scanner.nextLine().split("\\s+");
                int row = Integer.parseInt(tokens[0]);
                int col = Integer.parseInt(tokens[1]);
                if (row - 1 < numbers.size() && col < numbers.get(row - 1).length) {
                    System.out.println(numbers.get(row - 1)[col]);
                } else {
                    System.out.println("ERROR!");
                }
            }
            scanner.close();
        }
    }
    
  • + 0 comments
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
    
        ArrayList<String> arrayList = new ArrayList<>();
        while(n>0) {
    
            int a=scan.nextInt();
            if(a > 0) {
                arrayList.add(scan.nextLine());
            } else {
                arrayList.add("");
            }
    
            n--;
        }                
    
        int q = scan.nextInt();
    
        while(q>0){
    
            int x = scan.nextInt();
            int y = scan.nextInt();
    
            try{
                String str = arrayList.get(x-1);
    
                if(!str.isEmpty()) {
                    String[] strArr = str.trim().split(" ");
                    System.out.println(strArr[y-1]);
                } else {
                    System.out.println("ERROR!");    
                }
            } catch(IndexOutOfBoundsException e) {
                System.out.println("ERROR!");
            }
    
            q--;
        }
    
    
    }
    

    }

  • + 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();
    
X Tutup