Sort by

recency

|

825 Discussions

|

  • + 0 comments

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int totalLine=Integer.parseInt(br.readLine());
        ArrayList<Integer> alllines=new ArrayList<Integer>();
        for(int i=0;i<totalLine;i++)
        {
            String line=br.readLine();
            String linevalues[]=line.split(" ");
            for (String s:linevalues)
            {
                alllines.add(Integer.parseInt(s));
            }
        }
        int totalQueries=Integer.parseInt(br.readLine());
        for(int i=0;i<totalQueries;i++)
        {
            String line=br.readLine();
            String linevalues[]=line.split(" ");
            int lineNumber=Integer.parseInt(linevalues[0]);
            int position=Integer.parseInt(linevalues[1]);
            int k=0;
            boolean found=false;
            int foundValue=0;
            int totalNumbers=0,countInLine=0,line2=0;
    
            for(int traverse:alllines){
                k++;
    
                if(k==1) {
                    totalNumbers=traverse;
                    countInLine=0;
                    line2=1;
                    continue;
                }
                countInLine++;
                if(countInLine>totalNumbers) {
                    totalNumbers=traverse;
                     countInLine=0;
                     line2++;
                     continue;
                }
                if(lineNumber==line2 && countInLine==position) {
                    found=true;
                    foundValue=traverse;
                }
    
            }
            if(found==true){
                System.out.println(foundValue);
            } else {
                System.out.println("ERROR!");
            }
    
        }
    }
    

    }

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