개미 수열
public class Ant{
public static int[] array1;
public static int[] array2;
public static void main(String[] args){
int length = Integer.parseInt(args[0]);
array1 = new int[50];
array1[0] = 1;
for(int i = 0; i < length; i++){
for(int j = 0; j < array1.length; j++){
if(array1[j] != 0){
System.out.print(array1[j]+" ");
}
}
array1 = makeNextLine(array1);
System.out.println();
}
}
public static int[] makeNextLine(int[] array1){
int[] array2 = new int[50];
array2[0] = array1[0];
int index = 1;
int count = 1;
for(int i = 1; i < array1.length; i++){
if(array1[i-1] == array1[i]){
count++;
}else{
array2[index] = count;
index++;
array2[index] = array1[i];
index++;
count = 1;
}
}
return array2;
}
}