Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * This program is about find a house, where we can build among the trees.
  4. * here trees are represented as 1's and empty spaces as 0's. You need to
  5. * find a grid based on empty spaces.
  6. * @author Cerebri
  7. *
  8. */
  9.  
  10. public class LargestSquareHouse {
  11.  
  12. public static String largestsquarehouse(int[][] input1)
  13. {
  14. String value=null;
  15. int x=0;int r=0,c=0,count=0;
  16. int rows=input1.length;int columns=input1[0].length;
  17. for(int i=0;i<rows;i++){
  18. for(int j=0;j<columns;j++){
  19. if(x==input1[i][j]){
  20. count++; //counts only zeros.
  21. }
  22. else{
  23. count=0; //reset counter if there is 1 in between;
  24. }
  25. }
  26. if(count>1){
  27. r++; //it calculates row counts after successful zero's
  28. c=count; //it calculates column counts based on zero's
  29. }
  30. count=0; //resetting the counter to check in next row of the matrix.
  31. }
  32. value=r+"$"+c;
  33. return value;
  34. }
  35. public static void main(String [] args){
  36. Scanner in = new Scanner(System.in);
  37. String output;
  38. int ip1_rows = 0;
  39. int ip1_cols = 0;
  40. ip1_rows = Integer.parseInt(in.nextLine().trim());
  41. ip1_cols = Integer.parseInt(in.nextLine().trim());
  42.  
  43. int[][] ip1 = new int[ip1_rows][ip1_cols];
  44. for(int ip1_i=0; ip1_i<ip1_rows; ip1_i++) {
  45. for(int ip1_j=0; ip1_j<ip1_cols; ip1_j++) {
  46. ip1[ip1_i][ip1_j] = in.nextInt();
  47.  
  48. }
  49. }
  50. output = largestsquarehouse(ip1);
  51. System.out.println(String.valueOf(output));
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement