Cod sursa(job #2296627)

Utilizator SochuDarabaneanu Liviu Eugen Sochu Data 4 decembrie 2018 20:53:18
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#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]++;


    }

}