mellowdeep

test

Apr 15th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6. import java.util.stream.Stream;
  7.  
  8. public class _20150208_LegoBlocks {
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         try (Scanner scanner = new Scanner(System.in);) {
  13.             int numberOfLines = scanner.nextInt();
  14.             scanner.nextLine();
  15.  
  16.             List<List<String>> leftBlock = new ArrayList<>();
  17.             List<List<String>> rightBlock = new ArrayList<>();
  18.  
  19.             for (int i = 0; i < numberOfLines; i++) {
  20.                 List<String> temp = Stream.of(
  21.                         scanner.nextLine().trim().split("\\W+")).collect(
  22.                         Collectors.toList());
  23.  
  24.                 leftBlock.add(temp);
  25.             }
  26.             for (int i = 0; i < numberOfLines; i++) {
  27.                 List<String> temp = Stream
  28.                         .of(scanner.nextLine().trim().split("\\W+"))
  29.                         .sorted(Collections.reverseOrder())
  30.                         .collect(Collectors.toList());
  31.  
  32.                 rightBlock.add(temp);
  33.  
  34.             }
  35.             boolean formMatrix = true;
  36.  
  37.             long matrixLenght = leftBlock.get(0).size()
  38.                     + rightBlock.get(0).size();
  39.             long countSize = matrixLenght;
  40.             if (matrixLenght == 0) {
  41.                 formMatrix = false;
  42.             }
  43.             for (int i = 1; i < numberOfLines; i++) {
  44.                 if (matrixLenght != (leftBlock.get(i).size() + rightBlock
  45.                         .get(i).size())) {
  46.                     formMatrix = false;
  47.                 }
  48.                 countSize += (leftBlock.get(i).size() + rightBlock.get(i)
  49.                         .size());
  50.             }
  51.             if (formMatrix) {
  52.                 for (int i = 0; i < numberOfLines; i++) {
  53.                     System.out.print("[");
  54.                     System.out
  55.                             .printf("%s", String.join(", ", leftBlock.get(i)));
  56.                     System.out.print(", ");
  57.                     System.out.printf("%s",
  58.                             String.join(", ", rightBlock.get(i)));
  59.                     System.out.println("]");
  60.                 }
  61.             } else {
  62.                 System.out
  63.                         .printf("The total number of cells is: %d", countSize);
  64.             }
  65.         } catch (Exception e) {
  66.             System.out.println(e.toString());
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment