ユーザーが次数 4 の (部分的な) ラテン方陣を入力できるようにするプログラムを作成する必要があります。0 を使用して空のセルを表すことができます。ユーザーは、配置する番号、行と列を指定します。数字は、部分的なラテン方陣の特性に違反しない場合にのみ配置する必要があり、既に配置されている数字を書き換えるべきではありません。
現在、すべてゼロを出力しているマトリックスがあります。次に、これらの各値をユーザーが入力したものに置き換える必要があります。問題は、これを行う方法がわからないことです。
これが私のコードです:
#include <iostream>
using namespace std;
const int ORDER = 4;
void fill (int m[], int order);
void outputMatrix (int m[], int order);
void replaceValue (int m[], int order, int n, int row, int column);
int main(){
int matrix[ORDER];
int row;
int column;
int n;
fill (matrix, ORDER);
outputMatrix (matrix, ORDER);
do {
cout << "Enter the number to place, the row and the column, each seperated by a space: ";
cin >> n;
cin >> row;
cin >> column;
}while (n > 0 || n <= ORDER);
if (n <= 0 || n >= ORDER){
cout << "Thank you";
cout << endl;
}
return 0;
}
void fill (int m[], int order){
for (int i = 0; i < order*order; i++){
m[i] = 0;
}
}
void outputMatrix (int m[], int order){
int c = 0;
for (int i = 0; i < order*order; i++){
c++;
cout << m[i] << ' ';
if (c == order){
cout << endl;
c = 0;
}
}
cout << endl;
}
void replaceValue (int m[], int order, int n, int row, int column){
for (int i = 0; i < order; i++){
m[order] = m[row][column];
m[row][column] = n;
}
}
C++ で Matrix の値を置き換えるにはどうすればよいですか?