Advertisement
JmihPodvalbniy

Untitled

Dec 1st, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | Software | 0 0
  1. дз от 25.11.2024г.
  2.  
  3. 1)
  4. #include <iostream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.   int n;
  11.   cout << "Введите размер квадратной матрицы: ";
  12.   cin >> n;
  13.  
  14.   vector<vector<int>> matrix(n, vector<int>(n));
  15.   cout << "Введите элементы матрицы:" << endl;
  16.   for (int i = 0; i < n; ++i) {
  17.     for (int j = 0; j < n; ++j) {
  18.       cin >> matrix[i][j];
  19.     }
  20.   }
  21.  
  22.   bool symmetric = true;
  23.   for (int i = 0; i < n; ++i) {
  24.     for (int j = 0; j < n; ++j) {
  25.       if (matrix[i][j] != matrix[j][i]) {
  26.         symmetric = false;
  27.         break;
  28.       }
  29.     }
  30.     if (!symmetric) break;
  31.   }
  32.  
  33.   if (symmetric) {
  34.     cout << "Матрица симметрична." << endl;
  35.   } else {
  36.     cout << "Матрица несимметрична." << endl;
  37.   }
  38.  
  39.   return 0;
  40. }
  41.  
  42. 2)
  43. #include <iostream>
  44. #include <vector>
  45.  
  46. using namespace std;
  47.  
  48. pair<int, int> findElement(const vector<vector<int>>& arr, int target) {
  49.   int rows = arr.size();
  50.   int cols = arr[0].size(); // Предполагается, что все строки имеют одинаковое количество столбцов
  51.  
  52.   for (int i = 0; i < rows; ++i) {
  53.     for (int j = 0; j < cols; ++j) {
  54.       if (arr[i][j] == target) {
  55.         return make_pair(i, j);
  56.       }
  57.     }
  58.   }
  59.   return make_pair(-1, -1)
  60. }
  61.  
  62. int main() {
  63.   int rows, cols;
  64.   cout << "Введите количество строк: ";
  65.   cin >> rows;
  66.   cout << "Введите количество столбцов: ";
  67.   cin >> cols;
  68.  
  69.   vector<vector<int>> arr(rows, vector<int>(cols));
  70.   cout << "Введите элементы массива:" << endl;
  71.   for (int i = 0; i < rows; ++i) {
  72.     for (int j = 0; j < cols; ++j) {
  73.       cin >> arr[i][j];
  74.     }
  75.   }
  76.  
  77.   int target;
  78.   cout << "Введите элемент для поиска: ";
  79.   cin >> target;
  80.  
  81.   pair<int, int> pos = findElement(arr, target);
  82.  
  83.   if (pos.first == -1) {
  84.     cout << "Элемент не найден." << endl;
  85.   } else {
  86.     cout << "Элемент найден в строке " << pos.first << ", столбце " << pos.second << endl;
  87.   }
  88.  
  89.   return 0;
  90. }
  91.  
  92. 3)
  93. #include <iostream>
  94. #include <vector>
  95.  
  96. using namespace std;
  97.  
  98. int main() {
  99.   int rows, cols;
  100.   cin >> rows >> cols;
  101.  
  102.   vector<vector<int>> matrix(rows, vector<int>(cols));
  103.   for (int i = 0; i < rows; ++i) {
  104.     for (int j = 0; j < cols; ++j) {
  105.       cin >> matrix[i][j];
  106.     }
  107.   }
  108.  
  109.   vector<vector<int>> transposed(cols, vector<int>(rows));
  110.   for (int i = 0; i < rows; ++i) {
  111.     for (int j = 0; j < cols; ++j) {
  112.       transposed[j][i] = matrix[i][j];
  113.     }
  114.   }
  115.  
  116.   for (int i = 0; i < cols; ++i) {
  117.     for (int j = 0; j < rows; ++j) {
  118.       cout << transposed[i][j] << " ";
  119.     }
  120.     cout << endl;
  121.   }
  122.  
  123.   return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement