首页 > 其他 > 详细

上下排数问题

时间:2014-11-03 14:39:10      阅读:237      评论:0      收藏:0      [点我收藏+]
根据上排给出的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();

}


上下排数问题

原文:http://blog.csdn.net/zhouqinghe24/article/details/40739649

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!