Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _3_Largest3Rectangles {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- String inputSequence = scan.nextLine();
- inputSequence = inputSequence.replace("[", "");
- inputSequence = inputSequence.replace(" ", "");
- String[] rectangleSeq = inputSequence.split("]");
- int largestTotalArea = findTheLargestThreeConsecutiveRectangles(rectangleSeq);
- System.out.println(largestTotalArea);
- }
- private static int findTheLargestThreeConsecutiveRectangles(
- String[] rectangles) {
- int maxArea = 0;
- int totalArea;
- for (int i = 0; i + 2 < rectangles.length; i++) {
- totalArea = 0;
- for (int j = i; j < i + 3; j++) {
- String[] sides = rectangles[j].split("x");
- totalArea += (Integer.parseInt(sides[0]) * Integer
- .parseInt(sides[1]));
- }
- if (totalArea > maxArea) {
- maxArea = totalArea;
- }
- }
- return maxArea;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement