Cod sursa(job #1655500)

Utilizator SlevySlevoaca Stefan-Gabriel Slevy Data 18 martie 2016 00:47:55
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("combinari.in");
ofstream out("combinari.out");
int n,k;
const int NMAX = 19;
typedef int stiva[NMAX];
stiva st;
int vf = 1;

int ok()
{
    if(vf > 1)
        if(st[vf] <= st[vf-1])
            return 0;
    return 1;
}

void afisare()
{
    for(int i=1;i<=vf;i++)
        out<<st[i]<<" ";
    out<<"\n";
}

int main()
{
    in>>n>>k;
    in.close();
    st[vf] = 0;
    while(vf)
    {
        st[vf]++;
        if(st[vf] > n)
            vf--;
        else
        {
            if(ok())
            {
                if(vf==k)
                    afisare();
                else
                    st[++vf] = 0;
            }
        }
    }
    out.close();
    return 0;
}