// interDived.cpp : Defines the entry point for the console application.
//Writed by Johsnon Chen 2010/10/12
#include "stdafx.h"
#include <vector>
#include <iostream>
using namespace std;
vector<int> iVec;
void split_int(int n, int base)
{
if(n == 0)
{
cout << "find a combination: ";
for(vector<int>::size_type i= 0; i < iVec.size(); ++i)
cout << iVec[i] << " ";
cout << endl;
return;
}
else
{
for(int i = base + 1; i <= n; i++)
{
iVec.push_back(i);
split_int(n - i, i);
iVec.erase(--iVec.end());
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
split_int(6, 0);
return 0;
}
c++ 实现整数的拆分
最新推荐文章于 2024-05-10 22:02:58 发布
这是一个由Johsnon Chen于2010年10月12日编写的C++程序,用于将整数拆分成指定基数的组合。程序通过递归方式将整数n拆分为大于等于base的整数,展示所有可能的组合。
摘要由CSDN通过智能技术生成