简单的sort排序加记录数组,由于木棒的长度最长不超过1000,因此我们可以多设置一个数组b来记录各长度木棒的个数
放代码:
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int b[10005];
int main()
{
int n;
cin>>n;
memset(b,0,sizeof(b));
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
b[a[i]]++;
}
sort(b,b+10000);
int c=0;
for(int i=0;i<10000;i++)
{
if(b[i]) c++;
}
printf("%d %d\n",b[9999],c);
return 0;
}