Good day.
There is a list of arrays with indexing starting from zero. I also need that both in the list and in its arrays the indexing starts from 1. What is the simplest way to do this?
Each next array in the list is created by cloning one of the previous ones.
There must be only one class in the program - the main one, such is the specifics of the task.
Can I list the first element (i.e, with index 0) in advance before entering arrays to put null
so that the indexation of non-empty arrays starts from one?
public class Main implements Cloneable { public static void main(String[] args){ List<int[]> a = new ArrayList<int[]>(); Scanner reader = new Scanner(System.in); int n; for( ; ; ) { n = reader.nextInt(); if(n<100000) break; } int[] a0 = new int[n]; for (int i = 0; i < n; i++) a0[i] = reader.nextInt(); a.add(a0); int m; for( ; ; ) { m = reader.nextInt(); if(m<100000) break; } String[] request = new String[m]; for (int i = 0; i < m; i++){ request[i] = reader.next(); if ( request[i].equals("create")) { int version = reader.nextInt(); int position = reader.nextInt(); int symbol = reader.nextInt(); create(a, position, version, symbol); } else if (request[i].equals("get")) { int version = reader.nextInt(); int position = reader.nextInt(); System.out.println(get( a, position, version)); } } } public static void create(List<int[]> a, int position, int version, int symbol){ a.add((a.get(version)).clone()); int last=a.size()-1; a.get(last)[position]=symbol; } public static int get(List<int[]> a, int position, int version){ return a.get(version)[position]; } }