Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LargestRectangle {
- public static void main(String[] args) {
- // Scanner scanner = new Scanner(System.in);
- // String[] inputLine = scanner.nextLine().split(",");
- // String[][] matrix = new String[20][inputLine.length - 1];
- // int numberRows = 0;
- //
- // for (int row = 0; row < 20; row++) {
- // for (int col = 0; col < inputLine.length - 1; col++) {
- // matrix[row][col] = inputLine[col + 1];
- // }
- // inputLine = scanner.nextLine().split(",");
- // if (inputLine[0].equals("END")) {
- // numberRows = row + 1;
- // break;
- // }
- // }
- String[][] matrix =
- {
- {"xx", "a", "a", "a", "a", "a", "a"},
- {"a", "a", "z", "z", "a", "php", "a"},
- {"a", "a", "x", "x", "a", "a", "a"},
- {"xx", "a", "sql", "a", "a", "js", "a"},
- {"xx", "a", "a", "a", "a", "a", "a"},
- {"xx", "a", "z", "z", "a", "php", "w"}
- };
- int maxFoundElements = 0;
- int foundElements = 1;
- for (int row = 0; row < 6; row++) {
- for (int col = 0; col < matrix[0].length - 1; col++) {
- for (int moveRight = col; moveRight < matrix[0].length - 1; moveRight++) {
- if (foundElements > maxFoundElements) {
- maxFoundElements = foundElements;
- foundElements = 1;
- }
- if (matrix[row][moveRight].equals(matrix[row][moveRight + 1])) {
- foundElements++;
- for (int moveDown = row; moveDown < 6 - 1; moveDown++) {
- if (matrix[moveDown][moveRight + 1].equals(matrix[moveDown + 1][moveRight + 1])) {
- foundElements++;
- for (int moveLeft = moveRight + 1; moveLeft > 0; moveLeft--) {
- if (matrix[moveDown + 1][moveLeft].equals(matrix[moveDown + 1][moveLeft - 1])) {
- foundElements++;
- for (int moveUp = moveDown + 1; moveUp > 0; moveUp--) {
- if (matrix[moveUp][moveLeft - 1].equals(matrix[moveUp - 1][moveLeft - 1])) {
- foundElements++;
- } else {
- moveUp = 0;
- foundElements--;
- }
- }
- } else {
- moveLeft = 0;
- foundElements--;
- }
- }
- } else {
- moveDown = 6 - 1;
- foundElements--;
- }
- }
- } else {
- moveRight = matrix[0].length - 1;
- foundElements--;
- }
- }
- }
- }
- System.out.println(maxFoundElements);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement