一道网上看到的面试题(做着玩 用到递归了)
#include<iostream>
#include<vector>
using namespace std;
void out(int,int);
void main()
{
out(5,8);
}
void out(int a,int b)
{
static vector<int> result;
if(a<=0||b<=0)
return;
if(b>=a)
{
result.push_back(a);
int end=b-a;
int begin=a-1;
if(end>0)
{
out(begin,end);
}
if(end==0)
{
for(vector<int>::iterator i=result.begin();i!=result.end();i++)
cout<<*i<<' ';
cout<<endl;
}
result.pop_back();
out(begin,b);
}
else
{
int begin=a-1;
out(begin,b);
}
}