You are on page 1of 1

Repere :

conditii de validare
- cand un numar gasit se afla printre cifrele lui x
problema :
#include<iostream.h>
int n, sol=0,i,s,x[200],w;
void citire()
{
cout<<"w= ";cin>>w;
}
void INIT(int k)
{
x[k]=-1;
}
int EXISTA(int k)
{
if(x[k]<n) return 1;
else return 0;
}
int SOLUTIE (int k)
{
return 1;
}
int valid(int k)
{
for(i=1;i<=k;i++)
if((x[i]%10) != (w%10)) return 0;
return 1;
}
void TIPAR(int k)
{
sol++;
cout<<"Solutia "<<sol<<" : ";
for(i=1;i<=k;i++)
cout<<x[i]<<" ";
cout<<endl;
}
void BKT()
{
int k;
k=1;
INIT(k);
while(k>0)
if(EXISTA(k))
{
x[k]=x[k]+1;
if(valid(k))
if(SOLUTIE(k)) TIPAR(k);
else { k=k+1;
INIT(k);
}
}else k=k-1;
return;
}
int main()
{
citire();
BKT();
}

You might also like