c++ 实现整数的拆分
2010-10-12 22:19
169 查看
// 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;
}
//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++实现无限大整数的加法
- 巧用union实现整数高低位拆分
- 从易到难编写C++程序,(4)问题:实现一个大整数表示的BigInt类
- HDU 4002 Find the maximum(C++大整数实现+打表)
- C++实现两个大整数相加
- C/C++ 实现整数四则运算
- 大整数类C++实现——完整代码
- C++实现的大整数分解Pollard's rho算法程序
- 算法基础:整数拆分问题(Golang实现)
- C++实现高精度大整数(大数)的四则运算
- C/C++实现"输出100以内能被3整除且个位数为6的所有整数"
- 从易到难编写C++程序,(5)问题:实现满足各种需求的随机整数生成类RandCreater
- c++实现两个大整数相加(一)
- scanf/cin输入若干整数以回车结束,并存储,用C/C++实现
- [C++]第七次作业:实现一个大整数类BigInt
- 使用C++中string实现任意长度的正小数、整数之间加减法方法实例
- UTF-8编码的字符串拆分成单字、获取UTF-8字符串的字符个数的代码及原理(c++实现)
- 在2.5亿个整数中找出不重复的整数的C++实现源代码
- C++实现十六进制字符串转换为十进制整数的方法
- 大整数类c++实现