Ostatnie wpisy

main()
{
int width, height,points,i,j;
int factorial (int number_f);

/*****************creating the points TABLE***************************/

cout <<"The number must be INTEGER! (just like the contents NO. x )\n"
"(The more you give, the longer it will take to calculate them)\n";

cout << "\n\nHow many points do you have?\n";
cin >> points; 
cout << "\n";
int *tablica = new int[points];
for (int w=0 ; w<points ;w++) // user gives the points
{
cout << "NO." << (w+1) << ": ";
int a;
cin >> a;
tablica[w]=a;
}

/*******************CREATING TABLE FOR ALL POSSIBILITIES*************/
height = (factorial(points));
width = (points); 
int **tab = new int*[height]; // double pointer
for (int i = 0; i < height; i++) 
{
tab[i] = new int[width];
} 
i=0; j=0; 
int g=0; int z=0; 

/*********************************************/
/********************FILLING******************/
/*********************************************/

for (j=0 ; j < width ; j++) //... and to the next column
{ 
g=0;

/******fill column******/
for (i=0 ; i < height ; i++) 
{ 
/*** fill cell***/
for (int m=0 ; m<1 //check if the number repeats
{
if (g>=points){g=0;} // not to get out of table 
if (j>0)
{
for (int h=0 ; h < j ; h++)
{ 
if (g>=points){g=0;} 
if (tablica[g] == tab[i][h])
{z=1;} // z=1 - the number already 
// exists
} // z=0 - go ahead, it's ok
} 

if (z == 1)
{g++; z=0; /*if (g>points) g=0;*/}
else m++;
}

/*****************now we know what to write. But where?*******/
/*********/ 
if ( i==0 && j==0){tab[i][j] = tablica[g];} // for 1st cell 
/*********/ 
else if (i && ((i%(factorial(points-j-1)))==0)) // period
{
g++;
if (g>=points){g=0;}
/********/
for (int m=0 ; m<1 // period check
{
if (g>=points){g=0;}

if (j>0)
{
for (int h=0 ; h < j ; h++)
{ 
if (g>=points){g=0;} 
if (tablica[g] == tab[i][h])
{z=1;}
}
} 

if (z == 1){g++; z=0;}
/*********/ else m++; // get out of loop
}
tab[i][j] = tablica[g]; 
}
/*********/
else // otherwise
{tab[i][j] = tablica[g];}
}
}


/* ----------------------------------------------*/ 
/* ----------- DISPLAY OF THE TABLE -------------*/ 
/* ----------------------------------------------*/

cout << "\nThese are all the possibilities\n";

i=0 ;

while ( height - i ) //wyswietlamy cala tablice
{
j=0;
while ( width - j) 
{
cout << tab[i][j] << "\t";
j++;
}
cout << "\n";
i++;
}

cout <<"\n";
system ("pause");

}// END OF PROGRAM

int factorial (int number_f) // function 1
{
long wynik = 1;
for (int i=1 ; i<=number_f ; i++)
{
wynik = wynik * i;
}
return wynik;
}		
  1. Nie posiadasz obsługi JavaScript. Aby potwierdzić, że nie jesteś botem, wpisz tutaj wartość FDXRS
4programmers.net