Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int max_of_3(const int& a,const int& b,const int& c);
  7.  
  8. int main()
  9. {
  10. int n,m;
  11. srand(time(NULL));
  12. cout << "Введите Количество строк: " << endl;
  13. cin >> n;
  14. cout << "Введите Количество столбцов: " << endl;
  15. cin >> m;
  16. cout << "Массив: " << endl;
  17. int** p_arr = new int* [n];
  18. for(int i=0; i<n; i++)
  19. p_arr[i] = new int [m];
  20. for(int i=0; i<n; i++)
  21. {
  22. for(int j=0; j<m; j++)
  23. {
  24. p_arr[i][j]=rand()%10;
  25. cout <<p_arr[i][j] << " ";
  26. }
  27. cout << endl;
  28. }
  29. int** n_arr = new int* [n+2];
  30. for(int i=0; i<n+2; i++){
  31. n_arr[i] = new int [m+2];
  32. }
  33. for(int i=0; i<n+2; i++){
  34. for(int j=0; j<m+2; j++){
  35. n_arr[i][j]=0;
  36. }
  37. }
  38. for(int x=1, i=0; x<n+1; x++, i++){
  39. for(int y=1, j=0; y<m+1; y++, j++){
  40. n_arr[x][y]=p_arr[i][j];
  41. }
  42. }
  43. for (int j=1; j<m+1; j++){
  44. for(int i=1; i<n+1; i++){
  45. n_arr[i][j]=max_of_3(n_arr[i][j], n_arr[i-1][j], n_arr[i][j-1]);
  46. }
  47. }
  48. for(int i=0, x=1; i<n; i++,x++){
  49. for (int j=0, y=1; j<m; j++,y++){
  50. p_arr[i][j]=n_arr[x][y];
  51. }
  52. }
  53. cout << "Окончательный массив: " << endl;
  54. for(int i=0; i<n; i++)
  55. {
  56. for(int j=0; j<m; j++)
  57. {
  58. cout << p_arr[i][j] << " ";
  59. }
  60. cout << endl;
  61. }
  62. for(int i=0; i!=n; i++)
  63. delete[] p_arr[i];
  64. delete[] p_arr;
  65. }
  66.  
  67. int max_of_3(const int&a,const int&b,const int&c){
  68. if(a>b) {
  69. if (a>c) return a; else return c;
  70. }
  71. else {
  72. if (c>b) return c; else return b;
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement