Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int max_of_3(const int& a,const int& b,const int& c);
- int main()
- {
- int n,m;
- srand(time(NULL));
- cout << "Введите Количество строк: " << endl;
- cin >> n;
- cout << "Введите Количество столбцов: " << endl;
- cin >> m;
- cout << "Массив: " << endl;
- int** p_arr = new int* [n];
- for(int i=0; i<n; i++)
- p_arr[i] = new int [m];
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- p_arr[i][j]=rand()%10;
- cout <<p_arr[i][j] << " ";
- }
- cout << endl;
- }
- int** n_arr = new int* [n+2];
- for(int i=0; i<n+2; i++){
- n_arr[i] = new int [m+2];
- }
- for(int i=0; i<n+2; i++){
- for(int j=0; j<m+2; j++){
- n_arr[i][j]=0;
- }
- }
- for(int x=1, i=0; x<n+1; x++, i++){
- for(int y=1, j=0; y<m+1; y++, j++){
- n_arr[x][y]=p_arr[i][j];
- }
- }
- for (int j=1; j<m+1; j++){
- for(int i=1; i<n+1; i++){
- n_arr[i][j]=max_of_3(n_arr[i][j], n_arr[i-1][j], n_arr[i][j-1]);
- }
- }
- for(int i=0, x=1; i<n; i++,x++){
- for (int j=0, y=1; j<m; j++,y++){
- p_arr[i][j]=n_arr[x][y];
- }
- }
- cout << "Окончательный массив: " << endl;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- cout << p_arr[i][j] << " ";
- }
- cout << endl;
- }
- for(int i=0; i!=n; i++)
- delete[] p_arr[i];
- delete[] p_arr;
- }
- int max_of_3(const int&a,const int&b,const int&c){
- if(a>b) {
- if (a>c) return a; else return c;
- }
- else {
- if (c>b) return c; else return b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement