简单之整型数组排列组合




inline void __fastcall _Print(const unsigned int _uArea[], unsigned int _uMaxSize);
inline bool __cdecl _CmpVal(const unsigned char _sArea[], const unsigned char _dArea[], unsigned int _nLen);
unsigned int __cdecl _CompArray(/*const unsigned char _dArea[],*/ unsigned int _uMaxValue, unsigned int _uTypeSize);




inline void __fastcall _Print(const unsigned int _uArea[], unsigned int _uMaxSize)
{
 for (register unsigned int n = 0U; n < _uMaxSize; ++n)
 {
  printf("%u+", _uArea[n]);
 }
 printf("0\r\n");
 //::Sleep(100U);
}

inline bool __cdecl _CmpVal(const unsigned char _sArea[], const unsigned char _dArea[], unsigned int _nLen)
{
 if (memcmp(_sArea, _dArea, _nLen) == 0)
 {
  return true;
 }
 return false;
}

unsigned int __cdecl _CompArray(/*const unsigned char _dArea[],*/ unsigned int _uMaxValue, unsigned int _uTypeSize)
{
 unsigned int _uMemSize = (_uMaxValue * _uTypeSize);
 unsigned int * _uArea = (unsigned int *)malloc(_uMemSize);

 _uMemSize = _uMemSize - _uTypeSize;

 if (_uArea != NULL)
 {
  //if (_uMaxValue > 255U)
  //{
  for (register unsigned int i = 1U/*0U*/; i < _uMaxValue/*256U*/; ++i)
   {
    unsigned int _uCount = 0U;
    unsigned int _uIndex = 0U;
    register unsigned int _uNext = 0U;
    register unsigned int _uTmpVal = i;

    _uArea[_uNext++] = _uTmpVal;
    memset((_uArea + 1U), 0, _uMemSize);

    for (register unsigned j = i + 1U; j < _uMaxValue/*256U*/; ++j)
    {
     _uTmpVal += j;

     if (_uTmpVal < _uMaxValue)
     {
      _uArea[_uNext++] = j;
      continue;
     }
     else if (_uTmpVal == _uMaxValue && _uIndex != j)
     {
      _uIndex = j;
      _uArea[_uNext++] = j;
      _Print(_uArea, _uNext);
      _uNext -= (_uNext - 1U);
      j = (i + 1U) + _uCount++;
      _uTmpVal = i;
      continue;
     }
     else
     {
      _uTmpVal -= j--;
      _uTmpVal -= j;
      _uNext--;
      continue;
     }
    }
   }
  //}
  free(_uArea);
 }
 return 0U;
}



int _tmain(int argc, _TCHAR* argv[])
{
 //求1 - 4095结果为4096的不同排列组合
 _CompArray(4096U, sizeof(unsigned int));
 return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值