Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string.h>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- int n,m,temp,lastJ,row=0,colomn=0;
- srand((unsigned)time(0));
- cin>>n;
- cin>>m;
- int **p= new int*[n];
- for (int i=0;i<n;i++)
- {
- p[i]=new int[m];
- }
- for (int i=0;i<n;i++)
- for (int j=0;j<m;j++)
- p[i][j]=rand()%100;
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<m;j++)
- {
- cout.width(3);
- cout<<p[i][j]<<" ";
- }
- cout<<endl;
- }
- cout<<endl;cout<<endl;cout<<endl;
- // SORT
- for (int i=0;i<n;i++)
- for (int j=0;j<m;j++)
- {
- for (int I=0;I<n;I++)
- {
- for (int J=0;J<m-1;J++) // сортировка элементов в текущей строке
- {
- if (p[I][J]>p[I][J+1])
- {
- temp=p[I][J];
- p[I][J]=p[I][J+1];
- p[I][J+1]=temp;
- }
- }
- if (I<n-1 && p[I][m-1]>p[I+1][0] ) // последний и первый эл-ты в строке, проверка чтоб строка не была последней
- {
- temp=p[I][m-1];
- p[I][m-1]=p[I+1][0];
- p[I+1][0]=temp;
- }
- }
- }
- // END OF SORT
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<m;j++)
- {
- cout.width(3);
- cout<<p[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement