Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- дз от 25.11.2024г.
- 1)
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n;
- cout << "Введите размер квадратной матрицы: ";
- cin >> n;
- vector<vector<int>> matrix(n, vector<int>(n));
- cout << "Введите элементы матрицы:" << endl;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- cin >> matrix[i][j];
- }
- }
- bool symmetric = true;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (matrix[i][j] != matrix[j][i]) {
- symmetric = false;
- break;
- }
- }
- if (!symmetric) break;
- }
- if (symmetric) {
- cout << "Матрица симметрична." << endl;
- } else {
- cout << "Матрица несимметрична." << endl;
- }
- return 0;
- }
- 2)
- #include <iostream>
- #include <vector>
- using namespace std;
- pair<int, int> findElement(const vector<vector<int>>& arr, int target) {
- int rows = arr.size();
- int cols = arr[0].size(); // Предполагается, что все строки имеют одинаковое количество столбцов
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- if (arr[i][j] == target) {
- return make_pair(i, j);
- }
- }
- }
- return make_pair(-1, -1)
- }
- int main() {
- int rows, cols;
- cout << "Введите количество строк: ";
- cin >> rows;
- cout << "Введите количество столбцов: ";
- cin >> cols;
- vector<vector<int>> arr(rows, vector<int>(cols));
- cout << "Введите элементы массива:" << endl;
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- cin >> arr[i][j];
- }
- }
- int target;
- cout << "Введите элемент для поиска: ";
- cin >> target;
- pair<int, int> pos = findElement(arr, target);
- if (pos.first == -1) {
- cout << "Элемент не найден." << endl;
- } else {
- cout << "Элемент найден в строке " << pos.first << ", столбце " << pos.second << endl;
- }
- return 0;
- }
- 3)
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int rows, cols;
- cin >> rows >> cols;
- vector<vector<int>> matrix(rows, vector<int>(cols));
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- cin >> matrix[i][j];
- }
- }
- vector<vector<int>> transposed(cols, vector<int>(rows));
- for (int i = 0; i < rows; ++i) {
- for (int j = 0; j < cols; ++j) {
- transposed[j][i] = matrix[i][j];
- }
- }
- for (int i = 0; i < cols; ++i) {
- for (int j = 0; j < rows; ++j) {
- cout << transposed[i][j] << " ";
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement