Cod sursa(job #990489)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 28 august 2013 14:30:50
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <cstdio>

using namespace std;

int n,k,st[25];

inline void Afisare()
{
	int i;
	for(i=1;i<=k;i++)
		printf("%d ", st[i]);
	printf("\n");
}

int main()
{
	int top;
	bool cand;
	freopen ("combinari.in","r",stdin);
	freopen ("combinari.out","w",stdout);
	scanf("%d%d", &n,&k);
	top=1;st[top]=0;
	while(top>0)
	{
		cand=false;
		while(!cand && st[top]<n)
		{
			st[top]++;
			cand=true;
		}
		if(!cand)
			top--;
		else
			if(top==k)
				Afisare();
			else
			{
				top++;
				st[top]=st[top-1];
			}
	}
	return 0;
}