Pagini recente » Cod sursa (job #3225788) | Cod sursa (job #2876711) | Cod sursa (job #2824810) | Cod sursa (job #1939381) | Cod sursa (job #990489)
Cod sursa(job #990489)
#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;
}