Skip to content

Instantly share code, notes, and snippets.

@alucky0707
Created April 28, 2013 01:05
Show Gist options
  • Save alucky0707/5475390 to your computer and use it in GitHub Desktop.
Save alucky0707/5475390 to your computer and use it in GitHub Desktop.
AOJ 108
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N;
while((N = scan.nextInt()) != 0) {
int[] S = new int[N];
for(int i = 0; i < N; i++) {
S[i] = scan.nextInt();
}
int n = 0;
int[] prev = S;
int[] now = new int[N];
for( ; !Arrays.equals(prev, now);) {
n++;
if(n >= 2){
prev = now;
}
now = new int[N];
Map<Integer,Integer> mset = new HashMap<Integer,Integer>();
for(int i = 0; i < N; i++) {
if(mset.containsKey(prev[i])) {
mset.put(prev[i],mset.get(prev[i]).intValue()+1);
} else {
mset.put(prev[i], 1);
}
}
for(int i = 0; i < N; i++) {
now[i] = mset.get(prev[i]).intValue();
}
}
System.out.println(n-1);
for(int i = 0; i < N; i++) {
if(i > 0){
System.out.print(" ");
}
System.out.print(now[i]);
}
System.out.println();
}
scan.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment