Cod sursa(job #2430244)

Utilizator mariasmmskklns mariasmm Data 13 iunie 2019 14:57:59
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
vector <int> v;

int verifica(int k)
{
    int ok=1, i=0;
    while (ok&&i<v.size())
    {
        if (v[v.size()-1]>=k)
            ok=0;
        if (v[i]==k)
            ok=0;
        i++;
    }
    if (ok)
        return 1;
        return 0;
}

int main()
{

    ifstream f ("combinari.in");
    ofstream g ("combinari.out");
    int n, k, l=1, next=1;
    f>>n>>k;
    v.push_back(1);
    while (l!=-1)
    {
        while ((!verifica(next))&&(next<=n))
            next++;
        if (next<=n)
        {
            v.push_back(next);
            l++;
            next=1;
        } else
        {
            next=v[l-1]+1;
            v.pop_back();
            l--;
        }
        if (l==k)
        {
            for (int i=0; i<v.size(); i++)
                g<<v[i]<<" ";
            g<<"\n";
            next=v[k-1]+1;
            v.pop_back();
            l--;
        }
    }
    return 0;
}