Your job is to write a program that reads in the number k and the set S and then prints all possible games choosing numbers only from S.
8 1 2 3 5 8 13 21 34
0
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 4 5 6 7
1 3 4 5 6 7
2 3 4 5 6 7
1 2 3 5 8 13
1 2 3 5 8 21
1 2 3 5 8 34
1 2 3 5 13 21
1 2 3 5 13 34
1 2 3 5 21 34
1 2 3 8 13 21
1 2 3 8 13 34
1 2 3 8 21 34
1 2 3 13 21 34
1 2 5 8 13 21
1 2 5 8 13 34
1 2 5 8 21 34
1 2 5 13 21 34
1 2 8 13 21 34
1 3 5 8 13 21
1 3 5 8 13 34
1 3 5 8 21 34
1 3 5 13 21 34
1 3 8 13 21 34
1 5 8 13 21 34
2 3 5 8 13 21
2 3 5 8 13 34
2 3 5 8 21 34
2 3 5 13 21 34
2 3 8 13 21 34
2 5 8 13 21 34
3 5 8 13 21 34
while(cin>>t)
{
if(t==0) break;
if(flag) flag=0;
else cout<<endl;
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
using namespace std;
int num[100],ans[100],t;
bool cmp(int x,int y)
{
return x<y;
}
void dfs(int time,int position)
{
int i;
if(time==7)
{
for(i=1;i<time;i++)
{
if(i==1) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
cout<<endl;
return;
}
for(i=position+1;i<=t;i++)
{
ans[time]=num[i];
// cout<<'<'<<ans[time]<<'>';
dfs(time+1,i);
}
}
int main()
{
int i,flag=1;
while(cin>>t)
{
if(t==0) break;
if(flag) flag=0;
else cout<<endl;
for(i=1;i<=t;i++)
{
cin>>num[i];
}
sort(num+1,num+t,cmp);
// for(i=1;i<=t;i++) cout<<num[i];
// memset(vis,0,sizeof(vis));
// vis[1]=1;
dfs(1,0);
}
return 0;
}