您的位置:首页 > 编程语言 > C语言/C++

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: