Advertisement
Guest User

Untitled

a guest
May 17th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <string>
  6. #include <vector>
  7.  
  8. #include <time.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. //#include <algorithm>
  12.  
  13. using namespace std;
  14.  
  15. class MatrVect
  16. {
  17. public:
  18. int Row;
  19. int Col;
  20. int data;
  21.  
  22. vector <int> Clmn;
  23. vector < vector <int> > Mtr;
  24.  
  25. MatrVect()
  26. {
  27. cout << "Введите размерность матрицы Строки / Столбцы\t";
  28. cin >> Row >> Col;
  29. }
  30.  
  31. MatrVect(int rr, int cc)
  32. {
  33. Row= rr; Col= cc;
  34. }
  35.  
  36. void InitMatr()
  37. {
  38. srand (time(NULL));
  39.  
  40. for (int r0= 0; r0<Row; r0++)
  41. {
  42. for (int c0= 0; c0<Col; c0++)
  43. {
  44. //data = rand()%100);
  45. data=(r0+1)*10+(c0+1);
  46. Clmn.push_back(data);
  47. }
  48. Mtr.push_back(Clmn);
  49. Clmn.erase(Clmn.begin(), Clmn.end());
  50. }
  51. Mtr[Row/2][Col/2]= 100;
  52. Mtr[Row/3][Col/3]= -100;
  53. }
  54.  
  55. ////////////////////
  56.  
  57. void ShowMatr()
  58. {
  59. for (int r0= 0; r0<Row; r0++)
  60. {
  61. for (int c0= 0; c0<Col; c0++)
  62. {
  63. cout << Mtr[r0][c0] << "\t";
  64. }
  65. cout << endl;
  66. }
  67. }
  68.  
  69. //////////////////////
  70.  
  71. ~MatrVect() {}
  72.  
  73. /////////////////
  74.  
  75. void Func()
  76. {
  77. int rmax, sum, cmin, res;
  78.  
  79. sum= 0; rmax= 0; res= 0;
  80. for (int ind=0; ind<Col; ind++) res+=Mtr[0][ind];
  81.  
  82. for (int r= 1; r< Row; r++)
  83. {
  84. for (int ind=0; ind<Col; ind++) sum+=Mtr[r][ind];
  85. if (sum>res) { rmax = r; res = sum; sum = 0; }
  86. }
  87.  
  88. sum= 0; cmin= 0; res= 0;
  89. for (int ind=0; ind<Row; ind++) res+=Mtr[ind][0];
  90.  
  91. for (int c= 1; c< Col; c++)
  92. {
  93. for (int ind=0; ind<Row; ind++) sum+=Mtr[ind][c];
  94. if (sum<res) { cmin = c; res = sum; sum = 0; }
  95. }
  96.  
  97. cout << "Строка с максимальной суммой " << rmax << endl;
  98. cout << "Столбец с минимальной суммой " << cmin << endl;
  99. }
  100.  
  101. ///////////////////
  102. protected:
  103. private:
  104. };
  105.  
  106. ///////////////////////////////////
  107. int main(int argc, char **argv)
  108. {
  109.  
  110. system("chcp 1251 > nul");
  111. SetConsoleTitle(TEXT("Ответы"));
  112.  
  113. //MatrVect mv(5,5);
  114. MatrVect mv;
  115. mv.InitMatr();
  116. mv.ShowMatr();
  117. mv.Func();
  118.  
  119. cout<<endl; system("pause");
  120. return 0;
  121. }
  122.  
  123.  
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement