Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem_3 {
  4.  
  5. public static void main(String[] args) {
  6. Scanner see = new Scanner(System.in);
  7. int n = see.nextInt();
  8. see.nextLine();
  9. String[][] arr1 = new String[n][];
  10. String[][] arr2 = new String[n][];
  11. int[][] mas1 = new int[n][];
  12. int[][] mas2 = new int[n][];
  13. for (int i = 0; i < n; i++) {
  14. String in = see.nextLine().trim();
  15. arr1[i] = in.split(" +");
  16. }
  17. for (int i = 0; i < n; i++) {
  18. String in = see.nextLine().trim();
  19. arr2[i] = in.split(" +");
  20. }
  21. int length = arr1[0].length + arr2[0].length;
  22. int counter = 0;
  23. for (int i = 0; i < n; i++) {
  24. if(((arr1[i].length + arr2[i].length)) != length){
  25. counter++;
  26. }
  27. }
  28. String[][] fin = new String[n][length];
  29. if(counter == 0){
  30. for (int i = 0; i < n; i++) {
  31. for (int j = 0; j < arr1[i].length; j++) {
  32. fin[i][j] = arr1[i][j];
  33. }
  34. for (int j = arr2[i].length-1, k = arr1[i].length;j >= 0 && k < length; j--,k++) {
  35. fin[i][k] = arr2[i][j];
  36. }
  37. }
  38. }
  39. if(counter == 0){
  40. for (int i = 0; i < n; i++) {
  41. System.out.print("[");
  42. for (int j = 0; j < fin[i].length; j++) {
  43.  
  44. if(j == fin[i].length-1){
  45. System.out.print(fin[i][j]+"]");
  46. }
  47. else{
  48. System.out.print(fin[i][j]+", ");
  49. }
  50. }
  51. System.out.println();
  52. }
  53. }
  54. if(!(counter == 0)){
  55. int countcells = 0;
  56. for (int j = 0; j < n; j++) {
  57. countcells+= arr1[j].length;
  58. }
  59. for (int j = 0; j < n; j++) {
  60. countcells+= arr2[j].length;
  61. }
  62. System.out.println("The total number of cells is: " + countcells);
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement