Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- public class LargestThreeRectangles {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String[] inputLine = input.nextLine().split("[\\[\\D\\W\\]\\s]+");
- String[] inputLineCleaned = clean(inputLine);
- ArrayList<String[]> rectSides = new ArrayList<>();
- for (int i = 0; i < inputLineCleaned.length; i+=2){
- String[] temp = {inputLineCleaned[i],inputLineCleaned[i+1]};
- rectSides.add(temp);
- }
- Map<String,Long> combinations = new LinkedHashMap<>();
- for (int i = 0; i < rectSides.size()-2; i++){
- String[] tempOne = rectSides.get(i);
- String[] tempTwo = rectSides.get(i+1);
- String[] tempThree = rectSides.get(i+2);
- long areaOne = Long.parseLong(tempOne[0])*Long.parseLong(tempOne[1]);
- long areaTwo = Long.parseLong(tempTwo[0])*Long.parseLong(tempTwo[1]);
- long areaThree = Long.parseLong(tempThree[0])*Long.parseLong(tempThree[1]);
- long areaSum = areaOne+areaTwo+areaThree;
- String key = tempOne[0]+"*"+tempOne[1]+" + "
- +tempTwo[0]+"*"+tempTwo[1]+" + "
- +tempThree[0]+"*"+tempThree[1]+" = ";
- combinations.put(key, areaSum);
- }
- String test = Collections.max(combinations.entrySet(),
- (entry1, entry2) -> entry1.getValue() > entry2.getValue() ? 1 : -1).getKey();
- System.out.println(combinations.get(test));
- }
- public static String[] clean(final String[] v) {
- List<String> list = new ArrayList<String>(Arrays.asList(v));
- list.removeAll(Collections.singleton(""));
- return list.toArray(new String[list.size()]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement