Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem03 {
- @SuppressWarnings("resource")
- public static void main(String[] args) {
- Scanner scn = new Scanner(System.in);
- int numberOfRows = Integer.parseInt(scn.nextLine().trim());
- String[][] firstJagged = new String[numberOfRows][];
- String[][] secondJagged = new String[numberOfRows][];
- for (int i = 0; i < numberOfRows; i++) {
- firstJagged[i] = scn.nextLine().trim().split("\\s+");
- }
- for (int i = 0; i < numberOfRows; i++) {
- secondJagged[i] = scn.nextLine().trim().split("\\s+");
- }
- //check
- boolean matching = true;
- int combinedLength = firstJagged[0].length + secondJagged[0].length;
- for (int i = 1; i < numberOfRows; i++) {
- int nextLength = firstJagged[i].length + secondJagged[i].length;
- if (nextLength != combinedLength) {
- matching = false;
- break;
- }
- }
- //print accordingly
- if (matching) {
- for (int i = 0; i < numberOfRows; i++) {
- String output = "";
- for (int j = 0; j < firstJagged[i].length; j++) {
- output += firstJagged[i][j] + ", ";
- }
- for (int j = secondJagged[i].length - 1; j >= 0; j--) {
- output += secondJagged[i][j] + ", ";
- }
- System.out.println("[" + output.substring(0, output.length() - 2) + "]");
- }
- }
- else {
- int totalLength = 0;
- for (int i = 0; i < numberOfRows; i++) {
- totalLength += firstJagged[i].length + secondJagged[i].length;
- }
- System.out.println("The total number of cells is: " + totalLength);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement