Răspuns :
#include <iostream>
using namespace std;
int st[5],k;
void init()
{
st[k]=0;
}
int succesor()
{
if(st[k]<4)
{
st[k]++;
return 1;
}
return 0;
}
int valid()
{
for(int i=1;i<k;i++)
if(st[k]==st[i])
return 0;
return 1;
}
int solutie()
{
if(k==4)
return 1;
return 0;
}
void tipar()
{
for(int i=1;i<=4;i++)
cout<<st[i]<<' ';
cout<<'\n';
}
int main()
{
int as,ev;
k=1;
init();
while(k)
{
do
{
as=succesor();
if(as)
ev=valid();
}while(!(as&&ev||!as));
if(as)
if(solutie())
tipar();
else
{
k++;
init();
}
else
k--;
}
}
using namespace std;
int st[5],k;
void init()
{
st[k]=0;
}
int succesor()
{
if(st[k]<4)
{
st[k]++;
return 1;
}
return 0;
}
int valid()
{
for(int i=1;i<k;i++)
if(st[k]==st[i])
return 0;
return 1;
}
int solutie()
{
if(k==4)
return 1;
return 0;
}
void tipar()
{
for(int i=1;i<=4;i++)
cout<<st[i]<<' ';
cout<<'\n';
}
int main()
{
int as,ev;
k=1;
init();
while(k)
{
do
{
as=succesor();
if(as)
ev=valid();
}while(!(as&&ev||!as));
if(as)
if(solutie())
tipar();
else
{
k++;
init();
}
else
k--;
}
}
Vă mulțumim pentru vizita pe site-ul nostru dedicat Informatică. Ne dorim ca informațiile furnizate să vă fi fost utile. Dacă aveți întrebări sau aveți nevoie de suport suplimentar, nu ezitați să ne contactați. Revenirea dumneavoastră ne bucură, iar pentru acces rapid, adăugați-ne la favorite!