void so(int* arr,int size)
{
int m = 1;
/*int k = 0;
int j = 0;*/
int temp;
map<int, int,greater<int>> map1;//按关键字排序,从大到小
for (int i = 0; i < size - 1; i++)
{
if (arr[i] == arr[i + 1])
{
m++;
if (arr[i + 1] != arr[i + 2])
{
temp = arr[i + 1];
map1[m] = arr[i + 1];
}
}
else
{
m = 1;
}
}
auto i = map1.begin();
cout << i->first << " " << i->second << endl;
for (int j = 0; j < i->first; j++)
{
cout << i->second << " ";
}
}
测试代码
int arr[] = { 1,2,2,3,3,3,4,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
so(arr, 30);