Created
April 28, 2013 01:05
-
-
Save alucky0707/5475390 to your computer and use it in GitHub Desktop.
AOJ 108
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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