Cod sursa(job #1472913)

Utilizator alexandru.ghergutAlexandru-Gabriel Ghergut alexandru.ghergut Data 18 august 2015 01:39:40
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;

void nextCombination(int index, int value, int a[], int K, int N,
                                    ofstream &g)
{
    for (int i = value; i <= N; i++)
    {
        a[index] = i;
        if (index == K - 1)
        {
            for (int j = 0; j < K; j++)
                g << a[j] << " ";
            g << '\n';
        }
        else
            nextCombination(index + 1, i + 1, a, K, N, g);
    }
}

int main()
{
    int N, K;
    ifstream f("combinari.in");
    f >> N >> K;
    f.close();
    int a[K];

    ofstream g("combinari.out");
    nextCombination(0, 1, a, K, N, g);
    g.close();
    return 0;
}