Pagini recente » Cod sursa (job #3272808) | Cod sursa (job #3290336) | Cod sursa (job #3225396) | Cod sursa (job #3039165) | Cod sursa (job #2296627)
#include <fstream>
using namespace std;
ifstream fin ("combinari.in");
ofstream fout ("combinari.out");
int n,m,a[50],k,q,i,j;
int main()
{
fin>>n>>k;
if(n==1){
fout<<1;
return 0;
}
if(n==k)
{
for(i=1;i<=n;i++)
fout<<i<<' ';
return 0;
}
a[1]=1;
j=1;
while(a[1]<=n-k+1)
{
for(i=j+1;i<=k;i++)
a[i]=a[i-1]+1;
for(i=1;i<=k;i++)
fout<<a[i]<<' ';
fout<<'\n';
j=k;
while(a[j]>=n-k+j && a[j]>-1)
j--;
if(j==0)
break;
a[j]++;
}
}