Cod sursa(job #2171206)

Utilizator vladsirbu23Vlad Sirbu vladsirbu23 Data 15 martie 2018 11:33:32
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("combinari.in");
ofstream fout("combinari.out");
int n,st[20],k;
void init(int nivel)
{
    st[nivel]=st[nivel-1];
}
bool rezultat(int nivel)
{
    if(nivel==k)
        return 1;
    else
        return 0;
}
bool exista(int nivel)
{
    if(st[nivel]<n&&nivel<=k)
        return 1;
    else
        return 0;
}
void bk()
{
    int nivel,i;
    nivel=1;
    while(nivel>0)
    {
        if(exista(nivel))
        {
            st[nivel]++;
            if(rezultat(nivel))
            {
                for(i=1; i<=k; i++)
                    fout<<st[i]<<' ';
                fout<<'\n';
            }
            else
            {
                nivel++;
                init(nivel);
            }

        }
        else
        {
            nivel--;
        }
    }
}
int main()
{
    fin>>n>>k;
    bk();
}