Advertisement
another90sm

Untitled

Apr 12th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. public class LargestRectangle {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5. //        Scanner scanner = new Scanner(System.in);
  6. //        String[] inputLine = scanner.nextLine().split(",");
  7. //        String[][] matrix = new String[20][inputLine.length - 1];
  8. //        int numberRows = 0;
  9. //
  10. //        for (int row = 0; row < 20; row++) {
  11. //            for (int col = 0; col < inputLine.length - 1; col++) {
  12. //                matrix[row][col] = inputLine[col + 1];
  13. //            }
  14. //            inputLine = scanner.nextLine().split(",");
  15. //            if (inputLine[0].equals("END")) {
  16. //                numberRows = row + 1;
  17. //                break;
  18. //            }
  19. //        }
  20.         String[][] matrix =
  21.                 {
  22.                         {"xx", "a", "a", "a", "a", "a", "a"},
  23.                         {"a", "a", "z", "z", "a", "php", "a"},
  24.                         {"a", "a", "x", "x", "a", "a", "a"},
  25.                         {"xx", "a", "sql", "a", "a", "js", "a"},
  26.                         {"xx", "a", "a", "a", "a", "a", "a"},
  27.                         {"xx", "a", "z", "z", "a", "php", "w"}
  28.                 };
  29.  
  30.  
  31.         int maxFoundElements = 0;
  32.         int foundElements = 1;
  33.         for (int row = 0; row < 6; row++) {
  34.             for (int col = 0; col < matrix[0].length - 1; col++) {
  35.  
  36.                 for (int moveRight = col; moveRight < matrix[0].length - 1; moveRight++) {
  37.                     if (foundElements > maxFoundElements) {
  38.                         maxFoundElements = foundElements;
  39.                         foundElements = 1;
  40.                     }
  41.                     if (matrix[row][moveRight].equals(matrix[row][moveRight + 1])) {
  42.                         foundElements++;
  43.                         for (int moveDown = row; moveDown < 6 - 1; moveDown++) {
  44.                             if (matrix[moveDown][moveRight + 1].equals(matrix[moveDown + 1][moveRight + 1])) {
  45.                                 foundElements++;
  46.                                 for (int moveLeft = moveRight + 1; moveLeft > 0; moveLeft--) {
  47.                                     if (matrix[moveDown + 1][moveLeft].equals(matrix[moveDown + 1][moveLeft - 1])) {
  48.                                         foundElements++;
  49.                                         for (int moveUp = moveDown + 1; moveUp > 0; moveUp--) {
  50.                                             if (matrix[moveUp][moveLeft - 1].equals(matrix[moveUp - 1][moveLeft - 1])) {
  51.                                                 foundElements++;
  52.                                             } else {
  53.                                                 moveUp = 0;
  54.                                                 foundElements--;
  55.                                             }
  56.                                         }
  57.                                     } else {
  58.                                         moveLeft = 0;
  59.                                         foundElements--;
  60.                                     }
  61.                                 }
  62.                             } else {
  63.                                 moveDown = 6 - 1;
  64.                                 foundElements--;
  65.                             }
  66.                         }
  67.                     } else {
  68.                         moveRight = matrix[0].length - 1;
  69.                         foundElements--;
  70.                     }
  71.                 }
  72.             }
  73.         }
  74.  
  75.         System.out.println(maxFoundElements);
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement