这是哪错了

发布时间:2019-07-09 22:59:45
贴主:服务
热度:1
正在讨论:P2040 - 数组-13 题目传送门

服务 2019-07-09

#include<iostream>

#include<vector>

#include<random>

#include<algorithm>

using namespace std;

int main()

{

int n; cin >> n;

while (n--)

{

int m; cin >> m;

int* a = new int[m];

for (int i = 0; i < m; i++)

{

cin >> a[i];

/*random_device d; 随机测评  

a[i]=d() % 20;*/

}

vector <int>d;

sort(a, a +m);


int c = 0;

for (int i = 0; i < m; i++)

{

if (a[i] != a[i + 1])

{

c++;

d.push_back(a[i]);

}

}

int e = 0;

int* b = new int[c] {0};

for (int i = 0; i < c; i++)

{

for (int j = 0; j < m; j++)

{

if (d[i] == a[j])

{

b[i]++;

}

}

}

//for (int i = 0; i < c; i++)

//{

// cout << d[i] << " " << b[i]<<endl;随机测评

//}

int max = 0;

for (int i = 0; i < c; i++)

{

if (max < b[i]) { max = b[i]; }

}

bool f = false;

for (int i = 0; i < c; i++)

{

if (b[i] == max)

{

if (!f)

{

cout << d[i];

f = true;

}

else


{

cout << " " <<d[i];

}

}

}cout << endl;

}

return 0;

}

(0)

Copyright 2016 - 2024 XUJC ACM Team
闽ICP备2020022076号-1