#include<iostream>
using namespace std;
//以时间换空间,数组任意数字,求次数最多的数字
void search(int ary[],int len)
{
int sp[1000] = { 0 };
int index = 0;
int max = 0;
for (int i = 0; i < len; i++)
{
index = ary[i] - 1;
sp[index]++;
}
for (int i = 0; i < len; i++)
{
if(max < sp[i])
max = sp[i];
}
for (int i = 0; i < len; i++)
{
if (max == sp[i])
{
printf(" i = %d \n ", i + 1);
cout << " 出现次数: " << sp[i] << endl;
}
}
}
int main()
{
int iarray[] = { 1,2,3,4,5,6,7,2,3,4,2,34,2,3,4,2,5,6,4,2 };
search(iarray, sizeof(iarray) / sizeof(iarray[0]));
system("pause");
}