TizzyT

ExpandArray

Oct 8th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace RotateArray
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[][] test = new int[][]{new int[]{4,5,6,7},
  10.                                        new int[]{1,3,5,7},
  11.                                        new int[]{9,5,4,2}};
  12.  
  13.             PrintArray(test);
  14.  
  15.             int[][] result = ExpandArray(test);
  16.  
  17.             PrintArray(result);
  18.  
  19.             Console.ReadLine();
  20.         }
  21.  
  22.         public static int[][] ExpandArray(int[][] input)
  23.         {
  24.             int[][] result = new int[input.Length * 2][];
  25.             for (int y1 = 0, y2 = 0; y1 < input.Length; y1++, y2 += 2)
  26.             {
  27.                 result[y2] = new int[input[y1].Length * 2];
  28.                 for (int x1 = 0, x2 = 0; x1 < input[y1].Length; x1++, x2 += 2)
  29.                     result[y2][x2 + 1] = (result[y2][x2] = input[y1][x1]);
  30.                 result[y2 + 1] = (int[])result[y2].Clone();
  31.             }
  32.             return result;
  33.         }
  34.  
  35.         private static void PrintArray(int[][] input)
  36.         {
  37.             for (int y = 0; y < input.Length; y++)
  38.             {
  39.                 for (int x = 0; x < input[y].Length; x++)
  40.                     Console.Write(input[y][x] + ",");
  41.                 Console.WriteLine();
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment