Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
114579 彭士宝 求元素在矩阵中的位置 C++ Accepted 1 MS 276 KB 854 2025-03-22 17:24:09

Tests(4/4):


Code:

#include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; // 读取 n 和 m vector<vector<int>> matrix(n, vector<int>(n)); // 创建 n×n 的矩阵 // 读取矩阵的元素 for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> matrix[i][j]; } } // 查找元素 m bool found = false; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (matrix[i][j] == m) { found = true; cout << i << " " << j << endl; // 输出行和列的索引 break; } } if (found) { break; } } // 如果未找到元素 m if (!found) { cout << -1 << endl; } return 0; }