以下は、グリッド内の各文字をカウントする関数です。 この関数は、各文字のカウントを返すようにしたいが、私は立ち往生している。どうすれば他の方法を処理するのに必要な数を返すことができるのでしょうか?関数の返す方法特定の数値を返す
int getNeighborhood(const char** grid, int N, int row, int col, int& bCount, int& fCount, int& rCount, int& gCount){
int currRow;
int currCol;
int countB = 0;
int countF = 0;
int countR = 0;
int countG = 0;
//loop through all 8 grids surrounding the current row and column.
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++){
currRow = row + i; //current row.
currCol = col + i; //current column.
if(currRow >= 0 && currRow < N && currCol >= 0 && currCol < N){
if(grid[row][col] == 'B')
{
++countB;
}
if(grid[row][col] == 'F')
{
++countF;
}
if(grid[row][col] == 'R')
{
++countR;
}
if(grid[row][col] == 'G')
{
++countG;
}
}
}
//return statement required
}
あまり知識がありません...私は掲示板として基本的に行く必要があります....配列plsを使って説明することができますか? – Atinuke
@Atinuke編集済み! –