#include <stdio.h>
#include <stdlib.h>
int main(){
int i, j, k;
int a, b;
int **mat;
// ここで2次元配列の動的確保をする
mat
= (int **)malloc(a
* sizeof(int *)); // 行のポインタ配列を確保 for (i = 0; i < a; i++) {
mat
[i
] = (int *)malloc(b
* sizeof(int)); // 各行の列を確保 }
// ここで2次元配列に数値を代入する
k = 1; // 1から始める
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
mat[i][j] = k++;
}
}
// 以下の部分は表示の部分です
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
}
}
// メモリの解放
for (i = 0; i < a; i++) {
free(mat
[i
]); // 各行のメモリを解放 }
free(mat
); // 行のポインタ配列を解放
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAppbnQgbWFpbigpewogICAgaW50IGksIGosIGs7CiAgICBpbnQgYSwgYjsKICAgIGludCAqKm1hdDsKICAgIHNjYW5mKCIlZCAlZCIsICZhLCAmYik7CiAKICAgIC8vIOOBk+OBk+OBpzLmrKHlhYPphY3liJfjga7li5XnmoTnorrkv53jgpLjgZnjgosKICAgIG1hdCA9IChpbnQgKiopbWFsbG9jKGEgKiBzaXplb2YoaW50ICopKTsgLy8g6KGM44Gu44Od44Kk44Oz44K/6YWN5YiX44KS56K65L+dCiAgICBmb3IgKGkgPSAwOyBpIDwgYTsgaSsrKSB7CiAgICAgICAgbWF0W2ldID0gKGludCAqKW1hbGxvYyhiICogc2l6ZW9mKGludCkpOyAvLyDlkITooYzjga7liJfjgpLnorrkv50KICAgIH0KIAogICAgLy8g44GT44GT44GnMuasoeWFg+mFjeWIl+OBq+aVsOWApOOCkuS7o+WFpeOBmeOCiwogICAgayA9IDE7IC8vIDHjgYvjgonlp4vjgoHjgosKICAgIGZvciAoaSA9IDA7IGkgPCBhOyBpKyspIHsKICAgICAgICBmb3IgKGogPSAwOyBqIDwgYjsgaisrKSB7CiAgICAgICAgICAgIG1hdFtpXVtqXSA9IGsrKzsKICAgICAgICB9CiAgICB9CiAKICAgIC8vIOS7peS4i+OBrumDqOWIhuOBr+ihqOekuuOBrumDqOWIhuOBp+OBmQogICAgZm9yIChpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIGZvciAoaiA9IDA7IGogPCBiOyBqKyspIHsKICAgICAgICAgICAgcHJpbnRmKCIlZCAiLCBtYXRbaV1bal0pOwogICAgICAgIH0KICAgICAgICBwcmludGYoIlxuIik7CiAgICB9CiAKICAgIC8vIOODoeODouODquOBruino+aUvgogICAgZm9yIChpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIGZyZWUobWF0W2ldKTsgLy8g5ZCE6KGM44Gu44Oh44Oi44Oq44KS6Kej5pS+CiAgICB9CiAgICBmcmVlKG1hdCk7IC8vIOihjOOBruODneOCpOODs+OCv+mFjeWIl+OCkuino+aUvgogCiAgICByZXR1cm4gMDsKfQo=