Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #include <algorithm>
- int n,m;
- int num[100];
- int output[100];
- void comb(int nowIndex, int addIndex);
- int main()
- {
- while(cin>>n)
- {
- if(n==0)
- {
- break;
- }
- for(int i=0;i<n;i++)
- {
- cin>>num[i];
- }
- sort(num,num+n);
- cin>>m;
- comb(0,-1);
- cout<<endl;
- }
- return 0;
- }
- void comb(int nowIndex, int addIndex)
- {
- if(nowIndex==m)
- {
- for(int i=0;i<m;i++)
- {
- cout<<output[i]<<" ";
- }
- cout<<endl;
- }
- else
- {
- for(int i=addIndex+1;i<n;i++)
- {
- output[nowIndex]=num[i];
- comb(nowIndex+1,i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement