Hackpads are smart collaborative documents. Join Hackpad Now.

������������

126 days ago
Unfiled. Edited by AMBER , ������������ 126 days ago
AMBER "OXO"
"XOO"
"OOX"
 
 
"2X1"
"X31"
"12X"
 
1234
 
������������ vector<vector<char> > helper(vector<vector<char> > array){
 vector<vector<int> > result;
  • for(int i=0;i<array.size();i++){
  • for(int j=0;j<array[i].size();j++){
  • if(array[i][j]=="O" ) result[i][j]=0;
  • else result[i][j] = -1;
  • }
  •  for(int i=0;i<array.size();i++){
  • for(int j=0;j<array[i].size();j++){
  •  if(array[i][j]=="X" ) {
  • for(int m=-1;m<2;m++){
  • for(int n=-1;n<2;n++){
  •   if(i+m >= array.size() || i+m<0)continue;
  •  if(j+n >= array.size() || j+n<0)continue;
  •   result [i+m][j+n]++;
  • }
·  }
·  }
·  }
  • for(int i=0;i<array.size();i++)
  • for(int j=0;j<array[i].size();j++)
  •   if(array[i][j]=="O" ) array[i][j] = ‘0’+ result[i][j];
 
  • return array;
}
 

Contact Support



Please check out our How-to Guide and FAQ first to see if your question is already answered! :)

If you have a feature request, please add it to this pad. Thanks!


Log in / Sign up