Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. char asd[10][10];
  3.  
  4. void flood(int x, int y)
  5. {
  6. if (x<0 || y<0 || x > 9 || y > 9) return;
  7.  
  8. if (asd[x][y] != '0') return;
  9.  
  10. if (asd[x][y] == '0') asd[x][y] = 'p';
  11.  
  12. flood(x-1, y);
  13. flood(x+1, y);
  14. flood(x, y+1);
  15. flood(x, y-1);
  16. }
  17.  
  18. int main()
  19. {
  20. int X; // X coordinate of the cell to fill
  21. int Y; // Y coordinate of the cell to fill
  22. cin >> X >> Y; cin.ignore();
  23. int width;
  24. cin >> width; cin.ignore();
  25. int height;
  26. cin >> height; cin.ignore();
  27. for (int i = 0; i < height; i++) {
  28. string row; // One row of the map
  29. getline(cin, row);
  30. for (int j = 0; j < row.size();++j) asd[i][j] = row[j];
  31. }
  32.  
  33. flood(X,Y);
  34. int count = 0;
  35. for (int i = 0; i < 10; ++i)
  36. for (int j = 0; j < 10; ++j) if (asd[i][j] == 'p') count++;
  37.  
  38. // Write an action using cout. DON'T FORGET THE "<< endl"
  39. // To debug: cerr << "Debug messages..." << endl;
  40.  
  41. cout << count << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement