酷代码 AI
菜单
服务商

C++实现指定位置上方元素置零操作

以下是使用 C++ 实现的代码: ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; // 定义字符矩阵 vector<vector<char>> matrix(n, vector<char>(m)); // 读取字符矩阵 for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> matrix[i][j]; } } int x, y; cin >> x >> y; // 处理左上、上、右上元素 if (x > 0) { if (y > 0) { matrix[x - 1][y - 1] = '0'; } matrix[x - 1][y] = '0'; if (y < m - 1) { matrix[x - 1][y + 1] = '0'; } } // 输出处理后的矩阵 for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << matrix[i][j]; if (j < m - 1) { cout << " "; } } cout << endl; } return 0; } ``` ######[AI问答 | 351点数解答 | 2026-03-14 19:40:43]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]