Advertisement
liza271099l

Untitled

Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #pragma once
  2. #ifndef _ARRANGE_
  3. #define _ARRANGE_
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7. template <class T>
  8. class Arrange
  9. {
  10. private:
  11.     T * * ar;
  12.     int m;
  13.     int n;
  14.     T max;
  15.     T k;
  16. public:
  17.     Arrange();
  18.     void input();
  19.     void compare1();
  20.     void compare2();
  21.     ~Arrange();
  22. };
  23. #endif
  24. #include "Arrange.h"
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28. template<class T>
  29. Arrange<T>::Arrange()
  30. {
  31.     cin >> m;
  32.     cin>>n;
  33.     for (int i = 0; i < m; i++)
  34.     {
  35.         ar[i] = new T[n];
  36.     }
  37.     max = 0;
  38.     k = 0;
  39. }
  40. template<class T>
  41. void Arrange<T>::input()
  42. {
  43.     cout << "vvedite kolichestvo strok" << endl;
  44.     cin >> m;
  45.     cout << "vvedite kolichestvo stolbcov" << endl;
  46.     cin >> n;
  47.     for (int i = 0; i < m; i++)
  48.     {
  49.         for (int j = 0; j < n; j++)
  50.         {
  51.             ar[i][j] =1+rand()%10;
  52.  
  53.         }
  54.     }
  55.    
  56. }
  57. template<class T>
  58. void Arrange<T>::compare1()
  59. {
  60.     int ia = 0;
  61.     int ja = 0;
  62.     max = ar[1][0];
  63.     for (int i =1; i < m; i++)
  64.     {
  65.         for (int j = 0; j < n; j++)
  66.         {
  67.             if (i>=j)
  68.             {
  69.                 if (ar[i][j] > max)
  70.                 {
  71.                     max = ar[i][j];
  72.                     ia = i;
  73.                     ja = j;
  74.                 }
  75.                 else
  76.                 {
  77.                     max = ar[i + 1][j + 1];
  78.                     ia = i + 1;
  79.                     ja = j + 1;
  80.                 }
  81.  
  82.             }
  83.         }
  84.     }
  85.     cout << "max element" << max << "   " << "index" << ia << ";" << ja << endl;
  86. }
  87. template <class T>
  88. void Arrange<T>::compare2()
  89. {
  90.     int t = 1;
  91.     for (int j = 0; j < m; j++)
  92.     {
  93.         for (int i = 0; i < n;)
  94.         {
  95.             k = (k + ar[i][j]) / t;
  96.            
  97.             if (k[i] > k[i + 1])
  98.             {
  99.                 max = max + ar[i][j];
  100.             }
  101.             t++;
  102.             i++;
  103.  
  104.         }
  105.     }
  106.     cout << "max summ" << max << endl;
  107. }
  108. template <class T>
  109. Arrange<T>::~Arrange()
  110. {
  111. }
  112. #include <iostream>
  113. #include <iomanip>
  114. #include "Arrange.h"
  115. using namespace std;
  116. int main()
  117. {
  118.     Arrange<int> obg;
  119.     obg.input();
  120.     obg.compare1();
  121.     obg.compare2();
  122.     system("pause");
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement