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.
voidfillWithBombs(std::vector<std::string>&grid){for(inti=0;i<grid.size();i++){for(intj=0;j<grid[i].size();j++){if(grid[i][j]=='X'){grid[i][j]='.';}elseif(grid[i][j]=='.'){grid[i][j]='O';}}}}voidfillAndBlast(std::vector<std::string>&grid){for(inti=0;i<grid.size();i++){for(intj=0;j<grid[i].size();j++){if(grid[i][j]=='O'){grid[i][j]='X';if(i!=0){if(grid[i-1][j]!='O'){grid[i-1][j]='X';}}if(j!=0){if(grid[i][j-1]!='O'){grid[i][j-1]='X';}}if(i!=(grid.size()-1)){if(grid[i+1][j]!='O'){grid[i+1][j]='X';}}if(j!=(grid[i].size()-1)){if(grid[i][j+1]!='O'){grid[i][j+1]='X';}}}}}fillWithBombs(grid);}vector<string>bomberMan(intn,vector<string>grid){// Nothing happened yet, return original gridif((n==0)||(n==1))returngrid;// Full Bomb Gridif(n%2==0){fillWithBombs(grid);returngrid;}// First blast happenedif(n==3||n%4==3){fillAndBlast(grid);returngrid;}// Second Blast happenedif(n==5||n%4==1){fillAndBlast(grid);fillAndBlast(grid);returngrid;}}
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 →
cpp solution: