collection.cpp

来自「一个完整的彩票软件的源代码」· C++ 代码 · 共 90 行

CPP
90 行
字号
// Collection.cpp: implementation of the CCollection class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "lottery.h"
#include "Collection.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCollection::CCollection()
{

}

CCollection::~CCollection()
{

}

void CCollection::AddCollection(CCollection *pCol)
{
	int nSize=pCol->GetSize();
	for (int i=0; i<nSize; i++)
	{
		BYTE cByte=pCol->GetAt(i);
		if (Find(cByte) != -1) Add(cByte);
	}
}

int CCollection::Find(BYTE cByte)
{
	int nSize=GetSize();
	for (int i=0; i<nSize; i++)
	{
		if (cByte==GetAt(i)) return i;
	}
	return -1;
}

void CCollection::SubtractCollection(CCollection *pCol)
{
	int nSize=pCol->GetSize();
	for (int i=0; i<nSize; i++)
	{
		BYTE cByte=pCol->GetAt(i);
		int nIndex=Find(cByte);
		if (nIndex != -1) RemoveAt(nIndex,-1);
	}
}

void CCollection::CreateCompound(CArray<BYTE,BYTE>  *p, int nWidth)
{
	int nSize=GetSize();
	if (nSize < nWidth) return;
	ZeroMemory(m_com,30*sizeof(BYTE));
	for (int i=0; i<nSize; i++)
	{
		m_com[i]=GetAt(i);
	}
	m_nCount=0;
	Compound(nSize,nWidth,p, nWidth);
}

void CCollection::Compound(int n, int m,CArray<BYTE,BYTE>  *p, int nWidth)
{
	if (m==0)
	{
		for (int j=0; j<nWidth; j++) 
			p->Add(m_com2[j]);
		m_nCount++;
		return; 
	}
	else
	for (int i=n; i>=1; i--)
	{
		m_com2[m-1]=m_com[i-1];
		Compound(i-1,m-1,p, nWidth);
	}
	return;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?