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,sum;
- double tempDouble;
- 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()%2;
- 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
- double **a= new double*[2]; //массив со значениями ср ар столбцов
- for (int i=0;i<2;i++)
- {
- a[i]=new double[m];
- }
- for (int j=0;j<m;j++) //номер столбца
- a[0][j]=j;
- for (int j=0;j<m;j++)//среднее арфифметическое столбцов
- a[1][j]=0;
- for(int j=0;j<m;j++) // заполним массим а значениями ср ар
- {
- for (int i=0;i<n;i++)
- {
- a[1][j]+=p[i][j];
- }
- a[1][j]/=n;
- }
- for(int i=0;i<m;i++) // сортировка массива а
- {
- for (int j=0;j<n-i-1;j++)
- {
- if (a[1][j]>a[1][j+1])
- {
- tempDouble=a[1][j];
- a[1][j]=a[1][j+1];
- a[1][j+1]=tempDouble;
- temp=a[0][j];
- a[0][j]=a[0][j+1];
- a[0][j+1]=temp;
- }
- }
- }
- int **p2= new int*[n];//новый массив куда запишем отсортированный
- for (int i=0;i<n;i++)
- {
- p2[i]=new int[m];
- }
- for (int j=0;j<m;j++)// записываем в новвый массив старый с учетом сортировки
- {
- for (int i=0;i<n;i++)
- {
- p2[i][j]=p[i][(int)a[0][j]];
- }
- }
- // END OF SORT
- for (int i=0;i<n;i++)
- {
- for (int j=0;j<m;j++)
- {
- cout.width(3);
- cout<<p2[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement