#include <iostream> #include <Windows.h> #define row1 4 #define row2 3 #define column1 3 #define column2 3 int main() { int x1[row1][column1 + column2 - 1] = { {1, 2, 3, 0, 0}, {2, 3, 4, 0, 0}, {3, 4, 5, 0, 0}, {4, 5, 6, 0, 0} }; int x2[row2][column2] = { {1, 5, 6}, {2, 7, 8}, {4, 9, 10} }; int i = 0; int j = 0; while (i < row1) { if (x1[i][0] > x2[j][0]) { j++; } else if (x1[i][0] < x2[j][0]) { i++; } else { for (int k = 1; k < column2; k++) { x1[i][column1 + k - 1] = x2[j][k]; } i++; } } for (int i = 0; i < row1; i++) { for (int j = 0; j < column1 + column2 - 1; j++) { std::cout << x1[i][j] << ‘ ‘; } std::cout << std::endl; } system("pause"); return 1; }
时间: 2024-10-10 02:59:43