Advertisement
SergeyPGUTI

8.2.10(пузырек)

Feb 19th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string.h>
  4. #include<cstdlib>
  5. #include<ctime>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     int n,m,temp,lastJ,row=0,colomn=0;
  14.     srand((unsigned)time(0));
  15.     cin>>n;
  16.     cin>>m;
  17.     int **p= new int*[n];
  18.  
  19.     for (int i=0;i<n;i++)
  20.     {
  21.         p[i]=new int[m];
  22.     }
  23.  
  24.     for (int i=0;i<n;i++)
  25.         for (int j=0;j<m;j++)
  26.             p[i][j]=rand()%100;
  27.  
  28.  
  29.      for (int i=0;i<n;i++)
  30.     {
  31.  
  32.         for (int j=0;j<m;j++)
  33.             {
  34.                 cout.width(3);
  35.                 cout<<p[i][j]<<" ";
  36.             }
  37.             cout<<endl;
  38.     }
  39. cout<<endl;cout<<endl;cout<<endl;
  40.  
  41.     // SORT
  42.  
  43.     for (int i=0;i<n;i++)
  44.         for (int j=0;j<m;j++)
  45.         {
  46.                    for (int I=0;I<n;I++)
  47.                    {
  48.                        for (int J=0;J<m-1;J++) // сортировка элементов в текущей строке
  49.                         {
  50.                             if (p[I][J]>p[I][J+1])
  51.                             {
  52.                                 temp=p[I][J];
  53.                                 p[I][J]=p[I][J+1];
  54.                                 p[I][J+1]=temp;
  55.                             }
  56.                         }
  57.                         if (I<n-1 && p[I][m-1]>p[I+1][0]  ) // последний и первый эл-ты в строке, проверка чтоб строка не была последней
  58.                             {
  59.                                 temp=p[I][m-1];
  60.                                 p[I][m-1]=p[I+1][0];
  61.                                 p[I+1][0]=temp;
  62.  
  63.                             }
  64.                    }
  65.         }
  66.     // END OF SORT
  67.  
  68.  
  69.     for (int i=0;i<n;i++)
  70.     {
  71.  
  72.         for (int j=0;j<m;j++)
  73.             {
  74.                 cout.width(3);
  75.                 cout<<p[i][j]<<" ";
  76.             }
  77.             cout<<endl;
  78.     }
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement