1 solutions

  • 0
    @ 2025-11-5 16:37:44

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int a[200010],n;
    int main()
    {
    	//freopen("pcount.in","r",stdin);
    	//freopen("pcount.out","w",stdout);
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)
    	    scanf("%d",&a[i]);
    	sort(a+1,a+1+n);
    	a[n+1]=a[n]+1;
    	for(int i=1;i<=n;)
    	{
    		printf("%d ",a[i]);
    		int j=i;
    		for(j=i;a[j]==a[i];j++);
    			printf("%d\n",j-i);
    		i=j;
    	}
    	//getchar();
    	//getchar();
    }
    
    

    Pascal :

    var a:array[1..2000000] of integer; s,max:int64; i,n:longint;
      begin
      readln(n);
      max:=-1;
      for i:=1 to n do
        begin
          readln(s);
          inc(a[s]);
          if max<s then max:=s;
        end;
      for i:=1 to max do
        if a[i]<>0 then writeln(i,' ',a[i]);
      end.
    
    • 1

    Information

    ID
    17885
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By