SHOW:
|
|
- or go back to the newest paste.
1 | #include "stdafx.h" | |
2 | #include "iostream" | |
3 | #include "cstdio" | |
4 | #include "stdlib.h" | |
5 | #include "iomanip" | |
6 | using namespace std; | |
7 | ||
8 | void FillMassive(int **ary, int Index1, int Index2); | |
9 | int GetZeroIndex(int **ary, int Index1, int Index2); | |
10 | void PrintMassive(int **ary, int Index1, int Index2); | |
11 | int RemoveZeroString(int **ary, int Index1, int Index2); | |
12 | ||
13 | int main() | |
14 | { | |
15 | int Index1; | |
16 | int Index2; | |
17 | int n; | |
18 | int **ary; | |
19 | cout << "vvedite kolichestvo strok = "; | |
20 | cin >> Index1; | |
21 | cout << "vvedite kolichestvo stolbzov = "; | |
22 | cin >> Index2; | |
23 | srand(time(NULL)); | |
24 | ary = new int *[Index1]; // массив указателей | |
25 | for (int i = 0; i < Index1; i++) | |
26 | { | |
27 | ary[i] = new int[Index2]; // инициализация указателей | |
28 | } | |
29 | FillMassive(ary, Index1, Index2); | |
30 | PrintMassive(ary, Index1, Index2); | |
31 | cout << endl; | |
32 | cout << endl; | |
33 | cout << endl; | |
34 | int b=RemoveZeroString(ary, Index1, Index2); | |
35 | PrintMassive(ary, Index1-b, Index2); | |
36 | cin >> n; | |
37 | } | |
38 | void FillMassive(int **ary, int Index1, int Index2) | |
39 | { | |
40 | // работа с массивом | |
41 | for (int i = 0; i < Index1; i++) | |
42 | { | |
43 | for (int j = 0; j < Index2; j++) | |
44 | { | |
45 | ary[i][j] = rand() % 10 - rand() % 10; | |
46 | } | |
47 | } | |
48 | } | |
49 | void PrintMassive(int **ary, int Index1, int Index2) | |
50 | { | |
51 | for (int i = 0; i < (Index1 - 1); i++) | |
52 | { | |
53 | for (int j = 0; j < Index2; j++) | |
54 | { | |
55 | cout << ary[i][j] << " "; | |
56 | } | |
57 | cout << endl; | |
58 | } | |
59 | } | |
60 | ||
61 | ||
62 | int GetZeroIndex(int **ary, int Index1, int Index2){ | |
63 | for (int i = 0; i < Index1; i++) | |
64 | { | |
65 | bool zero = true; | |
66 | for (int j = 0; j < Index2; j++) | |
67 | { | |
68 | if (ary[i][j] != 0) | |
69 | { | |
70 | zero = false; | |
71 | break; | |
72 | } | |
73 | } | |
74 | if (zero) return i; | |
75 | } | |
76 | return -1; | |
77 | } | |
78 | ||
79 | ||
80 | int RemoveZeroString(int **ary, int Index1, int Index2) | |
81 | { | |
82 | int n = 0; | |
83 | int zeroIndex = GetZeroIndex(ary, Index1, Index2); | |
84 | if (zeroIndex == -1 || zeroIndex == (Index1 - 1)) | |
85 | { | |
86 | //cout << "No zero string found"; | |
87 | return 0; | |
88 | } | |
89 | for (int i = zeroIndex; i < (Index1 - 1); i++) | |
90 | { | |
91 | for (int j = 0; j < Index2; j++) | |
92 | { | |
93 | - | int aryIndex = 0; |
93 | + | ary[i][j] = ary[i + 1][j]; |
94 | - | if (i < zeroIndex){ |
94 | + | |
95 | - | aryIndex = i; |
95 | + | |
96 | - | } |
96 | + | |
97 | - | else |
97 | + |