Cod sursa(job #910455)

Utilizator deresurobertoFMI - Deresu Roberto deresuroberto Data 10 martie 2013 20:14:10
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include<cstdio>
int n,i,k,v[20];
bool ok;

void afisare()
{
	for(i=1;i<=k;i++) printf("%d ",v[i]);
	printf("\n");
}

void cont()
{
	ok=true;
	for(i=1;i<k;i++)
		if(v[i]>=v[k])ok=false;
}

bool succesor()
{
	bool ok1;
	ok1=false;
	if(v[k]<n){
		ok1=true;
		v[k]++;
		v[k+1]=0;
	}
	if (ok1==true) return true;
	else return false;
}


int main()
{
	freopen("submultimi.in","r",stdin);
	freopen("submultimi.out","w",stdout);
	scanf("%d",&n);
	k=1;
	while(k>0){
		ok=false;
		while(not(ok) && succesor()) cont();
		if (ok==false)k--;
		else {
			afisare();
			k++;
		}
	}
	return 0;
}