Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- boolean equal = true;
- int rows = Integer.parseInt(input.nextLine());
- String[][] firstArray = new String[rows][];
- String[][] secondArray = new String[rows][];
- int totalLength = 0;
- for (int i = 0; i < rows; i++) {
- firstArray[i] = input.nextLine().trim().split("\\s+");
- totalLength += firstArray[i].length;
- }
- for (int j = 0; j < rows; j++) {
- secondArray[j] = input.nextLine().trim().split("\\s+");
- totalLength += secondArray[j].length;
- }
- int template = firstArray[0].length + secondArray[0].length;
- for (int k = 0; k < rows; k++) {
- if (firstArray[k].length + secondArray[k].length != template) {
- equal = false;
- }
- }
- if (equal == false) {
- System.out.println("The total number of cells is: " + totalLength);
- }
- else {
- for (int m = 0; m < rows; m++) {
- System.out.print("[");
- System.out.print(combine(firstArray[m], ", "));
- System.out.print(", ");
- Collections.reverse(Arrays.asList(secondArray[m]));
- System.out.print(combine(secondArray[m], ", "));
- System.out.println("]");
- }
- }
- }
- public static String combine(String[] s, String glue)
- {
- int k = s.length;
- if ( k == 0 )
- {
- return null;
- }
- StringBuilder out = new StringBuilder();
- out.append( s[0] );
- for ( int x=1; x < k; ++x )
- {
- out.append(glue).append(s[x]);
- }
- return out.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment