Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * This program is about find a house, where we can build among the trees.
- * here trees are represented as 1's and empty spaces as 0's. You need to
- * find a grid based on empty spaces.
- * @author Cerebri
- *
- */
- public class LargestSquareHouse {
- public static String largestsquarehouse(int[][] input1)
- {
- String value=null;
- int x=0;int r=0,c=0,count=0;
- int rows=input1.length;int columns=input1[0].length;
- for(int i=0;i<rows;i++){
- for(int j=0;j<columns;j++){
- if(x==input1[i][j]){
- count++; //counts only zeros.
- }
- else{
- count=0; //reset counter if there is 1 in between;
- }
- }
- if(count>1){
- r++; //it calculates row counts after successful zero's
- c=count; //it calculates column counts based on zero's
- }
- count=0; //resetting the counter to check in next row of the matrix.
- }
- value=r+"$"+c;
- return value;
- }
- public static void main(String [] args){
- Scanner in = new Scanner(System.in);
- String output;
- int ip1_rows = 0;
- int ip1_cols = 0;
- ip1_rows = Integer.parseInt(in.nextLine().trim());
- ip1_cols = Integer.parseInt(in.nextLine().trim());
- int[][] ip1 = new int[ip1_rows][ip1_cols];
- for(int ip1_i=0; ip1_i<ip1_rows; ip1_i++) {
- for(int ip1_j=0; ip1_j<ip1_cols; ip1_j++) {
- ip1[ip1_i][ip1_j] = in.nextInt();
- }
- }
- output = largestsquarehouse(ip1);
- System.out.println(String.valueOf(output));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement