#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j;
int a, b;
int **mat;
// 行数と列数を入力
// 2次元配列の動的確保
mat
= (int **)malloc(sizeof(int*) * a
); if (mat == NULL) {
printf("Memory allocation failed for rows.\n"); return -1;
}
// 各行に対するメモリを確保
for (i = 0; i < a; i++) {
mat
[i
] = (int *)malloc(sizeof(int) * b
); if (mat[i] == NULL) {
printf("Memory allocation failed for columns.\n"); return -1;
}
}
// 2次元配列に数値を代入
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
mat[i][j] = i * b + j; // 例として、i * b + jの値を代入
}
}
// 配列の表示
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
}
}
// メモリの解放
for (i = 0; i < a; i++) {
free(mat
[i
]); // 各行に確保したメモリを解放 }
free(mat
); // mat自体のメモリを解放
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBtYWluKCkgewogICAgaW50IGksIGo7CiAgICBpbnQgYSwgYjsKICAgIGludCAqKm1hdDsKCiAgICAvLyDooYzmlbDjgajliJfmlbDjgpLlhaXlipsKICAgIHNjYW5mKCIlZCAlZCIsICZhLCAmYik7CgogICAgLy8gMuasoeWFg+mFjeWIl+OBruWLleeahOeiuuS/nQogICAgbWF0ID0gKGludCAqKiltYWxsb2Moc2l6ZW9mKGludCopICogYSk7CiAgICBpZiAobWF0ID09IE5VTEwpIHsKICAgICAgICBwcmludGYoIk1lbW9yeSBhbGxvY2F0aW9uIGZhaWxlZCBmb3Igcm93cy5cbiIpOwogICAgICAgIHJldHVybiAtMTsKICAgIH0KCiAgICAvLyDlkITooYzjgavlr77jgZnjgovjg6Hjg6Ljg6rjgpLnorrkv50KICAgIGZvciAoaSA9IDA7IGkgPCBhOyBpKyspIHsKICAgICAgICBtYXRbaV0gPSAoaW50ICopbWFsbG9jKHNpemVvZihpbnQpICogYik7CiAgICAgICAgaWYgKG1hdFtpXSA9PSBOVUxMKSB7CiAgICAgICAgICAgIHByaW50ZigiTWVtb3J5IGFsbG9jYXRpb24gZmFpbGVkIGZvciBjb2x1bW5zLlxuIik7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICB9CgogICAgLy8gMuasoeWFg+mFjeWIl+OBq+aVsOWApOOCkuS7o+WFpQogICAgZm9yIChpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIGZvciAoaiA9IDA7IGogPCBiOyBqKyspIHsKICAgICAgICAgICAgbWF0W2ldW2pdID0gaSAqIGIgKyBqOyAvLyDkvovjgajjgZfjgabjgIFpICogYiArIGrjga7lgKTjgpLku6PlhaUKICAgICAgICB9CiAgICB9CgogICAgLy8g6YWN5YiX44Gu6KGo56S6CiAgICBmb3IgKGkgPSAwOyBpIDwgYTsgaSsrKSB7CiAgICAgICAgZm9yIChqID0gMDsgaiA8IGI7IGorKykgewogICAgICAgICAgICBwcmludGYoIiVkICIsIG1hdFtpXVtqXSk7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KCiAgICAvLyDjg6Hjg6Ljg6rjga7op6PmlL4KICAgIGZvciAoaSA9IDA7IGkgPCBhOyBpKyspIHsKICAgICAgICBmcmVlKG1hdFtpXSk7ICAvLyDlkITooYzjgavnorrkv53jgZfjgZ/jg6Hjg6Ljg6rjgpLop6PmlL4KICAgIH0KICAgIGZyZWUobWF0KTsgIC8vIG1hdOiHquS9k+OBruODoeODouODquOCkuino+aUvgoKICAgIHJldHVybiAwOwp9Cg==