Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. /*lolsort*/
  2. #include <iostream>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. int block[5] [5];
  9. int fix[5] [5];
  10. int rowcount=0;
  11. int COLCOUNT=0;
  12. int TOTALCOUNT=0;
  13. int min;
  14.  
  15. for(int row=0; row<5; row++) {
  16.  
  17. for(int col=0; col<5; col++) {
  18.  
  19. block[row] [col]=rand();
  20.  
  21. }
  22. }
  23.  
  24. while(TOTALCOUNT<25) {
  25.  
  26. //get a value that has not been used
  27.  
  28. for(int row=0; row<5; row++) {
  29.  
  30. for(int col=0; col<5; col++) {
  31.  
  32. if(block[row] [col]) min=block[row] [col];
  33.  
  34. }
  35. }
  36.  
  37. //compare to intial array
  38.  
  39. for(int row=0; row<5; row++) {
  40.  
  41. for(int col=0; col<5; col++) {
  42.  
  43. if((block[row] [col]<min) && (block[row] [col]!=0)) min=block[row] [col];
  44. }
  45. }
  46.  
  47. //put value in array in ascending order
  48.  
  49. fix[rowcount] [COLCOUNT]=min;
  50.  
  51. //remove from initial array
  52.  
  53. for(int row=0; row<5; row++) {
  54.  
  55. for(int col=0; col<5; col++) {
  56.  
  57. if(block[row] [col]==min) block[row] [col]=0;
  58.  
  59. }
  60. }
  61.  
  62. TOTALCOUNT++;
  63. COLCOUNT++;
  64.  
  65. if(COLCOUNT==5){
  66.  
  67. COLCOUNT=0;
  68.  
  69. rowcount++;
  70. }
  71.  
  72.  
  73.  
  74.  
  75. }
  76.  
  77. //display
  78.  
  79. for(int row=0; row<5; row++) {
  80.  
  81. for(int col=0; col<5; col++) {
  82.  
  83. cout << fix[row] [col] <<" ";
  84.  
  85. }
  86.  
  87. cout <<"\n";
  88.  
  89. }
  90.  
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement