We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticstring[]cavityMap(string[]grid){for(inti=1;i<grid.Length-1;i++){for(intj=1;j<grid[i].Length-1;j++){intmiddleUpper=(int)char.GetNumericValue(grid[i-1][j]);intleft=(int)char.GetNumericValue(grid[i][j-1]);intright=(int)char.GetNumericValue(grid[i][j+1]);intmiddleUnder=(int)char.GetNumericValue(grid[i+1][j]);varadjacent=newint[4]{middleUpper,left,right,middleUnder};if(adjacent.Any(a=>a<0))continue;//smaller than 0 if X in adjacent cellintij=(int)char.GetNumericValue(grid[i][j]);if(adjacent.All(a=>a<ij))//Can use StringBuilder instead(faster?)grid[i]=grid[i].Remove(j,1).Insert(j,"X");}}returngrid;}
Cavity Map
You are viewing a single comment's thread. Return to all comments →
C# read as string