Created
February 16, 2018 12:45
-
-
Save Dviejopomata/f8b5cf7e69f79ba834dba9615c8d79dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace poc_c_ | |
{ | |
class Program | |
{ | |
const int filas = 5; | |
const int columnas = 4; | |
static int[,] matriz = new int[filas, columnas]; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello"); | |
var program = new Program(); | |
for (int i = 0; i < filas; i++) | |
{ | |
for (int j = 0; j < columnas; j++) | |
{ | |
var rnd = new Random(); | |
matriz[i, j] = rnd.Next(5, 10); | |
} | |
} | |
program.print(matriz); | |
program.shift(matriz, shiftNum); | |
Console.WriteLine("NEW"); | |
Console.WriteLine("--------------------------------"); | |
program.print(matriz); | |
// int[] m = new int[4] { 1, 2, 3, 4 }; | |
// program.shiftRowToLeft(m); | |
// Console.WriteLine("TO LEFT"); | |
// Console.WriteLine("--------------------------------"); | |
// Console.WriteLine($"Array {m[0]} {m[1]} {m[2]} {m[3]}"); | |
// m = new int[4] { 1, 2, 3, 4 }; | |
// program.shiftRowToRight(m); | |
// Console.WriteLine("TO RIGHT"); | |
// Console.WriteLine("--------------------------------"); | |
// Console.WriteLine($"Array {m[0]} {m[1]} {m[2]} {m[3]}"); | |
} | |
void print(int[,] matriz) | |
{ | |
for (int i = 0; i < filas; i++) | |
{ | |
for (int j = 0; j < columnas; j++) | |
{ | |
Console.Write(string.Format("{0} ", matriz[i, j])); | |
} | |
Console.Write(Environment.NewLine + Environment.NewLine); | |
} | |
} | |
void shiftRowToRight(int[] matriz) | |
{ | |
var tmp = matriz[matriz.Length - 1]; | |
for (int i = matriz.Length - 2; i >= 0; i--) | |
{ | |
matriz[i + 1] = matriz[i]; | |
} | |
matriz[0] = tmp; | |
} | |
void shiftRowToLeft(int[] matriz) | |
{ | |
var tmp = matriz[0]; | |
for (int i = 0; i < matriz.Length - 1; i++) | |
{ | |
matriz[i] = matriz[i + 1]; | |
} | |
matriz[matriz.Length - 1] = tmp; | |
} | |
void shift(int[,] matriz, int num) | |
{ | |
for (int i = 0; i < filas; i++) | |
{ | |
int[] m = new int[4]; | |
for (int j = 0; j < columnas; j++) | |
{ | |
m[j] = matriz[i, j]; | |
} | |
shiftRowToRight(m); | |
for (int j = 0; j < columnas; j++) | |
{ | |
matriz[i, j] = m[j]; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment