Cod sursa(job #180939)

Utilizator xtremespeedzeal xtreme Data 17 aprilie 2008 17:53:55
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include<iostream.h>
#include<fstream.h>


int n,k,st[20],as,ev,i,h,j,aux;

void succesor()
	{
	if(st[k]<n)
			{st[k]++;as=1;}
		else
			as=0;
	}
int main()
	{
	fstream f("combinari.in",ios::in),g("combinari.out",ios::out);
	f>>n>>h;
	k=1;st[k]=0;
	while(k>0)
		{
		succesor();
		if(as==1)
			{
			if(k==h)
				{
				for(i=1;i<=h;i++)
					g<<st[i]<<" ";
				g<<"\n";
				}
			else
				{aux=st[k];k++;st[k]=aux;}
			}
		else
			k--;
		}
	f.close();g.close();
	}