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.
voidtryExplode(std::vector<string>&src,inti,intj){size_trows=src.size();size_tcolumns=src[0].size();if(i<0||j<0||i>=rows||j>=columns){return;}src[i][j]='.';}vector<string>makeFullGrid(size_trows,size_tcolumns){std::stringfullRow;fullRow.insert(0,columns,'O');return{rows,fullRow};}std::vector<string>detonate(std::vector<string>const&src){size_trows=src.size();size_tcolumns=src[0].size();autodst=makeFullGrid(rows,columns);for(inti=0;i<rows;++i){for(intj=0;j<columns;++j){if(src[i][j]=='O'){tryExplode(dst,i+1,j);tryExplode(dst,i-1,j);tryExplode(dst,i,j+1);tryExplode(dst,i,j-1);tryExplode(dst,i,j);}}}returndst;}vector<string>bomberMan(intn,vector<string>grid){size_trows=grid.size();size_tcolumns=grid[0].size();if(n<=1){returngrid;}if(n%2==0){returnmakeFullGrid(rows,columns);}if(n%4==3){returndetonate(grid);}if(n%4==1){autoresult=detonate(grid);returndetonate(result);}throwstd::runtime_error("could not solve");}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Bomberman Game
You are viewing a single comment's thread. Return to all comments →
c++