Recent post
Pastebin details
  • Unicode support
  • Syntax highlighting
  • Diff
  • Download support
  • Upload support
Posted by Arabaaaabbbaaa, 09-01-2010 13:11
  1. main()
  2. {
  3. int width, height,points,i,j;
  4. int factorial (int number_f);
  5.  
  6. /*****************creating the points TABLE***************************/
  7.  
  8. cout <<"The number must be INTEGER! (just like the contents NO. x )\n"
  9. "(The more you give, the longer it will take to calculate them)\n";
  10.  
  11. cout << "\n\nHow many points do you have?\n";
  12. cin >> points;
  13. cout << "\n";
  14. int *tablica = new int[points];
  15. for (int w=0 ; w<points ;w++) // user gives the points
  16. {
  17. cout << "NO." << (w+1) << ": ";
  18. int a;
  19. cin >> a;
  20. tablica[w]=a;
  21. }
  22.  
  23. /*******************CREATING TABLE FOR ALL POSSIBILITIES*************/
  24. height = (factorial(points));
  25. width = (points);
  26. int **tab = new int*[height]; // double pointer
  27. for (int i = 0; i < height; i++)
  28. {
  29. tab[i] = new int[width];
  30. }
  31. i=0; j=0;
  32. int g=0; int z=0;
  33.  
  34. /*********************************************/
  35. /********************FILLING******************/
  36. /*********************************************/
  37.  
  38. for (j=0 ; j < width ; j++) //... and to the next column
  39. {
  40. g=0;
  41.  
  42. /******fill column******/
  43. for (i=0 ; i < height ; i++)
  44. {
  45. /*** fill cell***/
  46. for (int m=0 ; m<1 //check if the number repeats
  47. {
  48. if (g>=points){g=0;} // not to get out of table
  49. if (j>0)
  50. {
  51. for (int h=0 ; h < j ; h++)
  52. {
  53. if (g>=points){g=0;}
  54. if (tablica[g] == tab[i][h])
  55. {z=1;} // z=1 - the number already
  56. // exists
  57. } // z=0 - go ahead, it's ok
  58. }
  59.  
  60. if (z == 1)
  61. {g++; z=0; /*if (g>points) g=0;*/}
  62. else m++;
  63. }
  64.  
  65. /*****************now we know what to write. But where?*******/
  66. /*********/
  67. if ( i==0 && j==0){tab[i][j] = tablica[g];} // for 1st cell
  68. /*********/
  69. else if (i && ((i%(factorial(points-j-1)))==0)) // period
  70. {
  71. g++;
  72. if (g>=points){g=0;}
  73. /********/
  74. for (int m=0 ; m<1 // period check
  75. {
  76. if (g>=points){g=0;}
  77.  
  78. if (j>0)
  79. {
  80. for (int h=0 ; h < j ; h++)
  81. {
  82. if (g>=points){g=0;}
  83. if (tablica[g] == tab[i][h])
  84. {z=1;}
  85. }
  86. }
  87.  
  88. if (z == 1){g++; z=0;}
  89. /*********/ else m++; // get out of loop
  90. }
  91. tab[i][j] = tablica[g];
  92. }
  93. /*********/
  94. else // otherwise
  95. {tab[i][j] = tablica[g];}
  96. }
  97. }
  98.  
  99.  
  100. /* ----------------------------------------------*/
  101. /* ----------- DISPLAY OF THE TABLE -------------*/
  102. /* ----------------------------------------------*/
  103.  
  104. cout << "\nThese are all the possibilities\n";
  105.  
  106. i=0 ;
  107.  
  108. while ( height - i ) //wyswietlamy cala tablice
  109. {
  110. j=0;
  111. while ( width - j)
  112. {
  113. cout << tab[i][j] << "\t";
  114. j++;
  115. }
  116. cout << "\n";
  117. i++;
  118. }
  119.  
  120. cout <<"\n";
  121. system ("pause");
  122.  
  123. }// END OF PROGRAM
  124.  
  125. int factorial (int number_f) // function 1
  126. {
  127. long wynik = 1;
  128. for (int i=1 ; i<=number_f ; i++)
  129. {
  130. wynik = wynik * i;
  131. }
  132. return wynik;
  133. }
Your Name

Remember me

Syntax highlighting
Expire



Source code


Your browser does not support JavaScript. Please, enter this code in that field: FRKMTHKMPW:
Upload

Copyright © 2000-2006 by Coyote Group 0.9.3-pre3
Page generation: 0.0143 sek. (sql queries: 6)