题目连接:http://acm.pku.edu.cn/JudgeOnline/problem?id=2245
题目就是要按照字典序打印n个数中取出m个数的组合,递归即可完成。
#include <iostream>
using namespace std;
int num[12],res[6],i,n;
void Print(int cur,int s)
{
if(cur == 6)
{
int i;
cout << res[0];
for(i = 1;i < 6;++i)
cout << ' ' << res[i];
cout << endl;
}
else
{
int i;
for(i = s;i < n;++i)
{
res[cur] = num[i];
Print(cur+1,i+1);
}
}
}
int main()
{
freopen("in.txt","r",stdin);
while(cin >> n,n)
{
for(i = 0;i < n;++i)
cin >> num[i];
Print(0,0);
cout << endl;
}
return 0;
}