上下排數問題

根據上排給出的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();

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章