Загрузил zvarcev.igor

код программы

Реклама
#include <iostream>
using namespace std;
class array1 {
public:
int m;
int n;
int** arr;
int** arr11;
int* arr21;
int** arr12;
int* arr22;
int** arr13;
int* arr23;
int* arr3;
array1(int n1, int m1, int p11, int p22) {
n = n1;
m = m1;
arr = new int* [n];
arr11 = new int* [n];
arr12 = new int* [n];
arr13 = new int* [n];
arr21 = new int[n];
arr22 = new int[n];
arr23 = new int[n];
arr3 = new int[m];
int p1 = p11;
int p2 = p22;
int tmp = 0;
for (int i = 0; i < n; i++) { arr[i] = new int[m]; }
for (int i = 0; i < n; i++) { arr11[i] = new int[m]; }
for (int i = 0; i < n; i++) { arr12[i] = new int[m]; }
for (int i = 0; i < n; i++) { arr13[i] = new int[m]; }
for (int i = 0; i < n; ++i) { for (int j = 0; j < m; j++) { arr11[i][j] = 0; } }
for (int i = 0; i < n; ++i) { for (int j = 0; j < m; j++) { arr12[i][j] = 0; } }
for (int i = 0; i < n; ++i) { for (int j = 0; j < m; j++) { arr13[i][j] = 0; } }
for (int i = 0; i < n; ++i) { arr21[i] = 0; }
for (int i = 0; i < n; ++i) { arr22[i] = 0; }
for (int i = 0; i < n; ++i) { arr23[i] = 0; }
for (int i = 0; i < m; ++i) { arr3[i] = rand() % (p2 - p1 + 1) + p1; }
for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ++j) { if (arr3[j + 1] > arr3[j])
{
tmp = arr3[j + 1];
arr3[j + 1] = arr3[j];
arr3[j] = tmp;
}
}
}
for (int i = 0; i < n; ++i) { for (int j = 0; j < m; j++) { arr[i][j] = arr3[j]; } }
int kol = (n * m / 4);
int i = 0, j = 0;
while (kol != 0) {
i = rand() % (n-1) + 1;
j = rand() % m + 0;
arr[i][j] = -1;
--kol;
}
}
void sort1() {
int tmp1 = 0,tmp2 = 0;
int* tmparr = new int[n];
for (int q = 0; q < m; q++) {
for (int i = 0; i < m; i++) {
tmp1 = 0;
tmp2 = 0;
for (int j = 0; j < n; j++) {
if (arr[j][i] == -1)tmp1++;
if (arr[j][i + 1] == -1)tmp2++;
}
if ((tmp1 == 0) && (tmp2 != 0)) {
for (int z = 0; z < n; z++)tmparr[z] = arr[z][i];
for (int z = 0; z < n; z++)arr[z][i] = arr[z][i + 1];
for (int z = 0; z < n; z++)arr[z][i + 1] = tmparr[z];
}
}
}
delete[] tmparr;
}
void sort2() {
int tmp1 = 0, tmp2 = 0;
int* tmparr = new int[n];
for (int q = 0; q < m; q++) {
for (int i = 0; i < m; i++) {
tmp1 = 0;
tmp2 = 0;
for (int j = 0; j < n; j++) {
if (arr[j][i] == -1)tmp1++;
if (arr[j][i + 1] == -1)tmp2++;
}
if (tmp1 < tmp2) {
for (int z = 0; z < n; z++)tmparr[z] = arr[z][i];
for (int z = 0; z < n; z++)arr[z][i] = arr[z][i + 1];
for (int z = 0; z < n; z++)arr[z][i + 1] = tmparr[z];
}
}
}
delete[] tmparr;
}
bool bes(int i,int j) {
if (arr[i][j] == -1)return false; else return true;
}
void alg1(int** mas,int* mass) {
int min=mass[0];
int tmp = 0;
bool res = true;
for (int j = 0; j < m; j++) {
min = mass[0];
tmp = 0;
for (int i = 0; i < n; i++) { if ((min > mass[i]) && (bes(i,j))) { min = mass[i];
tmp = i;
} }
mas[tmp][j] = arr[tmp][j];
mass[tmp] += arr[tmp][j];
}
}
void ris1(int* mas,int z) {
for (int i = 0; i < z; i++)cout<<mas[i]<<" ";
}
void ris2(int**mas,int q,int w) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < q; j++) {
if (mas[j][i] > 0)cout << mas[j][i] << " "; else if (mas[j][i] < 0) cout << "oo" << " "; else cout << " ";
}
cout << endl;
}
}
void max(int*mas) {
int tmp = 0;
for (int i = 0; i < n; i++) {
if (tmp < mas[i]) { tmp = mas[i]; }
}
cout << endl << "max = " << tmp << endl;
}
void result() {
cout << "исходная матрица:" << endl;
ris2(arr,n,m);
cout << endl;
cout << "Распределение без изменений :" << endl;
alg1(arr11,arr21);
ris2(arr11, n, m);
cout << endl;
ris1(arr21,n);
max(arr21);
cout << endl;
sort1();
cout << "С учетом бесконечности :" << endl;
cout << "матрица:" << endl;
ris2(arr, n, m);
cout << endl;
alg1(arr12, arr22);
ris2(arr12, n, m);
cout << endl;
ris1(arr22, n);
max(arr22);
cout << endl;
sort2();
cout << "С учетом количества бесконечностей в строке :" << endl;
cout << "матрица:" << endl;
ris2(arr, n, m);
cout << endl;
alg1(arr13, arr23);
ris2(arr13, n, m);
cout << endl;
ris1(arr23, n);
max(arr23);
cout << endl;
}
~array1() {
for (int i = 0; i < 2; i++) { delete[] arr[i]; }
for (int i = 0; i < n; i++) { delete[] arr11[i]; }
for (int i = 0; i < n; i++) { delete[] arr12[i]; }
for (int i = 0; i < n; i++) { delete[] arr13[i]; }
delete[] arr21;
delete[] arr22;
delete[] arr23;
delete[] arr3;
}
};
int main()
{
setlocale(LC_ALL, "russian");
int n = 0, m = 0;\
cout << "введите количество процессов " << endl;
cin >> m;
cout << "введите количество процессоров " << endl;
cin >> n;
cout << endl;
cout << "введите диапазон: " << endl;
int p1 = 0, p2 = 0;
cin >> p1;
cin >> p2;
array1 mas(n, m, p1, p2);
mas.result();
system("pause");
return 0;
}
Скачать