根据上排给出的10个数,在其下排填出对应的十个数,
要求下排每个数都是上排那十个数在下排出现的次数。
#include <iostream>
using namespace std;
const int n = 10;
class BottomArr
{
public:
BottomArr()
{
pre = new int[n];
bottom = new int[n]{0};
for (int i = 0; i < n; i++)
{
pre[i] = i;
}
}
~BottomArr()
{
delete[]pre;
delete[] bottom;
}
void getArr()
{
bool flag = true;
while (flag)
{
flag = false;
for (int i = 0; i < n; i++)
{
int count = getcount(i);
if (count != bottom[i])
{
bottom[i] = count;
flag = true;
}
}
}
for (int i = 0; i < n; i++)
{
cout << bottom[i]<<" , ";
}
}
int getcount(int i)
{
int count = 0;
for (int j = 0; j < n; j++)
{
if (bottom[j] == i)
{
count++;
}
}
return count;
}
int *bottom;
int *pre;
};
void main()
{
BottomArr arr;
arr.getArr();
cout << "结束" << endl;
cin.get();
}