201412-1 门禁系统 Java

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer,Integer> readers = new HashMap<Integer,Integer>();
        for(int i=0;i<n;i++) {
            int num = sc.nextInt();
            if(readers.containsKey(num)) {
                readers.replace(num, readers.get(num)+1);
            }else {
                readers.put(num,1);
            }
            System.out.print(readers.get(num)+" ");
        }
        sc.close();
    }
}

猜你喜欢

转载自www.cnblogs.com/yu-jiawei/p/12343199.html