Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "cstdio"
- #include "stdlib.h"
- #include "iomanip"
- using namespace std;
- void FillMassive(int **ary, int Index1, int Index2);
- int GetZeroIndex(int **ary, int Index1, int Index2);
- void PrintMassive(int **ary, int Index1, int Index2);
- int RemoveZeroString(int **ary, int Index1, int Index2);
- int main()
- {
- int Index1;
- int Index2;
- int n;
- int **ary;
- cout << "vvedite kolichestvo strok = ";
- cin >> Index1;
- cout << "vvedite kolichestvo stolbzov = ";
- cin >> Index2;
- srand(time(NULL));
- ary = new int *[Index1]; // массив указателей
- for (int i = 0; i < Index1; i++)
- {
- ary[i] = new int[Index2]; // инициализация указателей
- }
- FillMassive(ary, Index1, Index2);
- PrintMassive(ary, Index1, Index2);
- cout << endl;
- cout << endl;
- cout << endl;
- int b=RemoveZeroString(ary, Index1, Index2);
- PrintMassive(ary, Index1-b, Index2);
- cin >> n;
- }
- void FillMassive(int **ary, int Index1, int Index2)
- {
- // работа с массивом
- for (int i = 0; i < Index1; i++)
- {
- for (int j = 0; j < Index2; j++)
- {
- ary[i][j] = rand() % 10 - rand() % 10;
- }
- }
- }
- void PrintMassive(int **ary, int Index1, int Index2)
- {
- for (int i = 0; i < (Index1 - 1); i++)
- {
- for (int j = 0; j < Index2; j++)
- {
- cout << ary[i][j] << " ";
- }
- cout << endl;
- }
- }
- int GetZeroIndex(int **ary, int Index1, int Index2){
- for (int i = 0; i < Index1; i++)
- {
- bool zero = true;
- for (int j = 0; j < Index2; j++)
- {
- if (ary[i][j] != 0)
- {
- zero = false;
- break;
- }
- }
- if (zero) return i;
- }
- return -1;
- }
- int RemoveZeroString(int **ary, int Index1, int Index2)
- {
- int n = 0;
- int zeroIndex = GetZeroIndex(ary, Index1, Index2);
- if (zeroIndex == -1 || zeroIndex == (Index1 - 1))
- {
- //cout << "No zero string found";
- return 0;
- }
- for (int i = zeroIndex; i < (Index1 - 1); i++)
- {
- for (int j = 0; j < Index2; j++)
- {
- ary[i][j] = ary[i + 1][j];
- }
- }
- return 1 + RemoveZeroString(ary, Index1, Index2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement