import java.util.*; public class Main{ public static void main(String[]args) { Scanner input =new Scanner(System.in); int n= input.nextInt(); int []ant=new int[n]; for(int i=0;i<n;i++) { ant[i]= input.nextInt(); } Arrays.sort(ant); HashMap<Integer,Integer> map=new HashMap<>(); for(int i:ant) { if(map.containsKey(i)) { int ans= map.get(i); ans++; map.put(i,ans); } else { map.put(i,1); } } Set<Integer> num=map.keySet(); Object [] ob = num.toArray(); Arrays.sort(ob); for(Object h:ob) { System.out.println(h+" "+map.get(h)); } } }
标签:map,NOIP2007,int,ob,ans,new From: https://www.cnblogs.com/liliczw2209/p/17157530.html