Cod sursa(job #1637289)

Utilizator serbanSlincu Serban serban Data 7 martie 2016 16:16:04
Problema Combinari Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>

using namespace std;

int n, k, s;
char x[100];

ifstream f("combinari.in");
ofstream g("combinari.out");

void bkt(int i, int last) {
    int lim = n - k + i;
    for(int j = last + 1; j <= lim; j ++) {
        if(j < 10) x[s] = j + '0', s ++, x[s] = ' ', s ++;
        else x[s] = '1', s ++, x[s] = j - 10 + '0', s ++, x[s] = ' ', s ++;
        if(i == k) {
            s --;
            x[s] = '\n';
            g << x;
            x[s] = 0;
            s ++;
        }
        else bkt(i + 1, j);
        if(j < 10) s -= 2;
        else s -= 3;
    }
}

int main()
{
    f >> n >> k;
    bkt(1, 0);
    return 0;
}