Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MatrizSubMatriz
- {
- class Program
- {
- /// <summary>
- /// Rellena un array de valores en orden ascendente, comenzando por el 1
- /// </summary>
- /// <param name="a">Array de cualquier tamaño</param>
- static void RellenaEnOrdenBi(int[,] a)
- {
- int i, j;
- int valor = 1;
- for (i = 0; i < a.GetLength(0); i++)
- {
- for (j = 0; j < a.GetLength(1); j++)
- {
- a[i, j] = valor;
- valor++;
- }
- }
- }
- /// <summary>
- /// Rellena un array 3x3 con números de tipo entero
- /// </summary>
- /// <returns>Devuelve matriz 3x3 con valores ingresados por consola</returns>
- static int[,] RellenaMatriz3x3() //Tenemos que pasar por parámetro un array 3x3
- {
- //Variables
- int[,] array = new int[3, 3];
- int i, j;
- int cont = 5;
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 3; j++)
- {
- array[i, j] = cont;
- cont++;
- }
- }
- return array;
- }
- /// <summary>
- /// Muestra por consola un array detallado
- /// </summary>
- /// <param name="a">Array de enteros vacío</param>
- static void EscribeArray(int[] a)
- {
- Console.Write("[");
- for (int i = 0; i < a.Length - 1; i++)
- {
- Console.Write(a[i] + ",");
- }
- Console.Write(a[a.Length - 1] + "]");
- }
- /// <summary>
- /// Función que imprime por pantalla array multidimensional de cualquier tamaño.
- /// </summary>
- /// <param name="a">Parámetro de la función y array de la misma</param>
- static void EscribeArrayBi(int[,] a)
- {
- int i, j;
- for (i = 0; i < a.GetLength(0); i++)
- {
- Console.Write("| ");
- for (j = 0; j < a.GetLength(1); j++)
- {
- Console.Write(a[i, j] + " ");
- }
- Console.WriteLine("|");
- }
- }
- /// <summary>
- /// Función que copia valores de array desde dos puntos de cota. Te copia los valores desde el inico al final
- /// de la cota
- /// </summary>
- /// <param name="a">Determina primer parámetro de la función y corresponde al array</param>
- /// <param name="inicio">Determina segundo parámetro y corresponde al inicio de la cota</param>
- /// <param name="fin">Determina tercer parámetro y corresponde al final de la cota</param>
- /// <returns>Devuelve copia de los elementos de la cota generada en el array</returns>
- static int[] SubArray(int[] a, int inicio, int fin)
- {
- int j, i;
- int cota = fin - inicio + 1;
- int[] b = new int[cota];
- i = 0;
- for (j = inicio; j <= fin; j++)
- {
- b[i] = a[j];
- i++;
- }
- return b;
- }
- static int[] CopiaMatrizEnArray(int[,] matriz, int tama)
- {
- int[] array = new int[tama];
- int cont = 0;
- for (int i = 0; i < matriz.GetLength(0); i++)
- {
- for (int j = 0; j < matriz.GetLength(1); j++)
- {
- array[cont] = matriz[i, j];
- cont++;
- }
- }
- return array;
- }
- static string CastingArrayToString(int[] array)
- {
- string str = "";
- for (int i = 0; i < array.Length; i++)
- {
- str = str + array[i].ToString();
- }
- return str;
- }
- static void MatrizContenedora()
- {
- //Variables
- int[,] matriz10x10 = new int[10, 10];
- int[] arrayEnteros = new int[9];
- int[,] matriz3x3;
- int[] arrayCopiaM100;
- int[] arrayCopiaM9;
- int pos0matriz3x3;
- string strArray100 = "";
- string strArray9 = "";
- string primerElementoGuardado = "";
- string trozoString = "";
- //Inicializamos matriz 10x10 y le damos valores
- RellenaEnOrdenBi(matriz10x10);
- //Mostramos por consola matriz10
- Console.WriteLine("Array bidimensional de 10x10:");
- Console.WriteLine();
- EscribeArrayBi(matriz10x10);
- //Pedimos al usuario los valores enteros para la submatriz 3x3 y le damos valores
- Console.WriteLine("Array bidimensional de 3x3:");
- Console.WriteLine();
- matriz3x3 = RellenaMatriz3x3();
- EscribeArrayBi(matriz3x3);
- Console.WriteLine();
- //Pasamos a un array de 1 dimensión los valores de matriz10x10
- arrayCopiaM100 = CopiaMatrizEnArray(matriz10x10, 100);
- arrayCopiaM9 = CopiaMatrizEnArray(matriz3x3, 9);
- //Pasamos los arrays a string para trabajar mejor con los datos
- strArray100 = CastingArrayToString(arrayCopiaM100);
- strArray9 = CastingArrayToString(arrayCopiaM9);
- //Si strArray9 (subMatriz3x3) está contenida en strArray100 (matriz10x10)
- if (strArray100.Contains(strArray9))
- {
- //Guarda el primer elemento de strArray9 (subMatriz3x3)
- primerElementoGuardado += strArray9[0];
- }
- //Hacemos un subString desde primerElementoGuardado+1 (pos[1] de matriz3x3) hasta el final de strArray100 (matriz10x10)
- //trozoString = strArray100.Substring();
- //El resultado final, coordenadas buscadas, serían las coordenadas del último elemento de strArray100
- //Tendríamos que comprobar eso en la matriz10x10
- }
- static void Main(string[] args)
- {
- //MatrizContenedora();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement