## 0011:数字统计

1000ms

100000kB

5 2 3 2 1 2

3 2 3 3 1 1 1

`import java.io.*;import java.util.*;public class Main{       public static void main(String args[]) throws Exception     {       Scanner cin = new Scanner(System.in);       int n = cin.nextInt();       long[] a= new long [n];       int[] vis= new int [n];       long[] b= new long [n];       long[] c= new long [n];       for(int i=1;i<=n;i++)         {         a[i] = cin.nextLong();         vis[i]=0;         }       int k=0;       for(int i=1;i<=n;i++)       {         long sum=1;         if(vis[i]==0)         {         for(int j=i+1;j<=n;j++)         {           if(a[i]==a[j])           {           sum++;           vis[j]=1;           }         }           k++;           b[k]=sum;           c[k]=a[i];         }                   vis[i]=1;       }       System.out.println(k);          for(int i=1;i<=k;i++)         {           System.out.println(c[i]+" "+b[i]);          }         }           }`

Map实现：

`import java.util.LinkedHashMap;import java.util.Scanner;import java.util.Set;public class Main {  static LinkedHashMap<Integer,Integer> map1=new LinkedHashMap<Integer,Integer>();  static void f(int key){    if(map1.containsKey(key)){      map1.put(key,map1.get(key)+1);    }    else{      map1.put(key,1);    }  }  public static void main(String[] args){  Scanner sc=new Scanner(System.in);  int m=sc.nextInt();  for(int i=0;i<m;i++){  f(sc.nextInt());  }  System.out.println(map1.size());  Set<Integer> keyset=map1.keySet();  for(Integer key:keyset){    System.out.println(key+" "+map1.get(key));  }`