Skip to content

Instantly share code, notes, and snippets.

@hyeonsupark
Last active April 18, 2016 07:24
Show Gist options
  • Save hyeonsupark/8c8ea703c4831920c8b1 to your computer and use it in GitHub Desktop.
Save hyeonsupark/8c8ea703c4831920c8b1 to your computer and use it in GitHub Desktop.
개미 수열
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int limit = input.nextInt();
ArrayList<Integer> currentList = new ArrayList<>();
ArrayList<Integer> nextList = new ArrayList<>();
currentList.add(1);
for (int i=0; i < limit; i++) {
int number = currentList.get(0);
int count = 0;
for (int j=0; j < currentList.size(); j++) {
if(number==currentList.get(j))
count++;
else {
nextList.add(count);
nextList.add(number);
number = currentList.get(j);
count = 1;
}
}
nextList.add(count);
nextList.add(number);
for (int k=0; k<currentList.size(); k++) {
System.out.print(currentList.get(k));
}
System.out.println();
currentList.clear();
currentList.addAll(nextList);
nextList.clear();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment