ch1_6_6求解门禁系统问题
import java.util.HashMap;
import java.util.Scanner;
public class ch1_6_6求解门禁系统问题 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int a[]=new int[n];
HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
for(int i=0;i<n;i++) {
int k=in.nextInt();
if(hm.containsKey(k)) {
a[i]=hm.get(k)+1;
hm.put(k,a[i]);
}
else {
a[i]=1;
hm.put(k, 1);
}
}
for(int i=0;i<n;i++) {
System.out.print(a[i]+" ");
}
}
}