Professional Documents
Culture Documents
Info
Info
Permutari P5
#include <iostream>
#include <fstream>
int main()
{
ofstream f("date.out");
cin >> n;
k = 1;st[k] = 0;
do{
while(st[k]<n){
ev = 1;st[k]++;
for(i=1;i<=k-1;i++)
if(st[k]==st[i])
ev = 0;
if(ev == 1)
if(k == n)
{
nr++;
if(nr<=5){
for(i=1;i<=k;i++)
f<<st[i]<< " ";
f<<endl;}
}
else{
k++;
st[k] = 0;
}
}
k--;
}while(k>0);
f.close();
return 0;
}
#include <iostream>
#include <fstream>
int main()
{
ofstream f("date.out");
cin >> n;
cin >> p;
k = 1;st[k] = 0;
do{
while(st[k]<n){
ev = 1;st[k]++;
for(i=1;i<=k-1;i++)
if(st[k]==st[i])
ev = 0;
if(ev == 1)
if(k == p)
{
//nr++;
//if(nr<=5){
for(i=1;i<=k;i++)
f<<st[i]<< " ";
f<<endl;}
//}
else{
k++;
st[k] = 0;
}
}
k--;
}while(k>0);
f.close();
return 0;
}
Primele 5 solutii
//Aranjamente de 5 luate cate 3
#include <iostream>
#include <fstream>
int main()
{
ofstream f("date.out");
cin >> n;
cin >> p;
k = 1;st[k] = 0;
do{
while(st[k]<n){
ev = 1;st[k]++;
for(i=1;i<=k-1;i++)
if(st[k]==st[i])
ev = 0;
if(ev == 1)
if(k == p)
{
nr++;
if(nr<=5){
for(i=1;i<=k;i++)
f<<st[i]<< " ";
f<<endl;}
}
else{
k++;
st[k] = 0;
}
}
k--;
}while(k>0);
f.close();
return 0;
}
3.Combinari de 5 luate cate 3; primele 5 solutii!
#include <iostream>
#include <fstream>
int main()
{
ofstream f("date.out");
cin >> n;
cin >> p;
k = 1;st[k] = 0;
do{
while(st[k]<n){
ev = 1;st[k]++;
for(i=1;i<=k-1;i++)
if(st[k]<=st[i])
ev = 0;
if(ev == 1)
if(k == p)
{
nr++;
if(nr<=5){
for(i=1;i<=k;i++)
f<<st[i]<< " ";
f<<endl;}
}
else{
k++;
st[k] = 0;
}
}
k--;
}while(k>0);
f.close();
return 0;
}