Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- public class _20150208_LegoBlocks {
- public static void main(String[] args) {
- try (Scanner scanner = new Scanner(System.in);) {
- int numberOfLines = scanner.nextInt();
- scanner.nextLine();
- List<List<String>> leftBlock = new ArrayList<>();
- List<List<String>> rightBlock = new ArrayList<>();
- for (int i = 0; i < numberOfLines; i++) {
- List<String> temp = Stream.of(
- scanner.nextLine().trim().split("\\W+")).collect(
- Collectors.toList());
- leftBlock.add(temp);
- }
- for (int i = 0; i < numberOfLines; i++) {
- List<String> temp = Stream
- .of(scanner.nextLine().trim().split("\\W+"))
- .sorted(Collections.reverseOrder())
- .collect(Collectors.toList());
- rightBlock.add(temp);
- }
- boolean formMatrix = true;
- long matrixLenght = leftBlock.get(0).size()
- + rightBlock.get(0).size();
- long countSize = matrixLenght;
- if (matrixLenght == 0) {
- formMatrix = false;
- }
- for (int i = 1; i < numberOfLines; i++) {
- if (matrixLenght != (leftBlock.get(i).size() + rightBlock
- .get(i).size())) {
- formMatrix = false;
- }
- countSize += (leftBlock.get(i).size() + rightBlock.get(i)
- .size());
- }
- if (formMatrix) {
- for (int i = 0; i < numberOfLines; i++) {
- System.out.print("[");
- System.out
- .printf("%s", String.join(", ", leftBlock.get(i)));
- System.out.print(", ");
- System.out.printf("%s",
- String.join(", ", rightBlock.get(i)));
- System.out.println("]");
- }
- } else {
- System.out
- .printf("The total number of cells is: %d", countSize);
- }
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment