Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. public static void check(int[][] buildingss) {
  2. int lastHeight = 0;
  3.  
  4. for (int x = 0; x < buildingss.length; x++) {
  5. for (int y = 0; y < buildingss[x].length; y++) {
  6. if (lastHeight == 0)
  7. lastHeight = buildingss[x][y];
  8. int val = checky(buildingss, x, y, lastHeight);
  9.  
  10. if (val != lastHeight && val != 0) {
  11. lastHeight = val;
  12. }
  13. }
  14. }
  15.  
  16. ArrayList end = new ArrayList(mappig.values());
  17. Collections.sort(end);
  18. for (int i = 0; i < end.size(); i++) {
  19. System.out.println(i + " " + end.get(i));
  20. }
  21. }
  22.  
  23.  
  24. public static int checky(int[][] buildingss, int x, int y, int lastHeight) {
  25. int val = buildingss[x][y];
  26.  
  27. if (val == 0)
  28. return 0;
  29.  
  30. if (val != lastHeight) {
  31. count++;
  32. mappig.putIfAbsent(count, 1);
  33. } else
  34. mappig.putIfAbsent(count, 0);
  35. if (val == lastHeight)
  36. mappig.put(count, mappig.get(count) + 1);
  37.  
  38. buildingss[x][y] = 0;
  39. if (x > 0)
  40. if (buildingss[x - 1][y] == val)
  41. checky(buildingss, x - 1, y, val);
  42. if (y > 0)
  43. if (buildingss[x][y - 1] == val)
  44. checky(buildingss, x, y - 1, val);
  45. if (x < buildingss.length - 1)
  46. if (buildingss[x + 1][y] == val)
  47. checky(buildingss, x + 1, y, val);
  48. if (y < buildingss.length - 1)
  49. if (buildingss[x][y + 1] == val)
  50. checky(buildingss, x, y + 1, val);
  51. return val;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement