Ir ao conteúdo
  • Cadastre-se

ivanRezende

Membro Júnior
  • Posts

    2
  • Cadastrado em

  • Última visita

Reputação

1
  1. 1 Uma imagem em preto e branco, de tamanho m x n, pode ser representada por uma matriz cujos elementos assumem valores no conjunto {0,1}. Dado um padrão representado por uma matriz 33 também assumindo valores em {0,1}, escreva uma função, ou trecho de código, que determine se o padrão existe ou não na imagem. (8 pontos) <code> using System; using System.IO; namespace Testes { class Program { static void Main(string[] args) { CriaMatriz("A.txt", 200, 350); CriaMatriz("B.txt", 3, 4); int[,] A = LerMatriz("A.txt"); int[,] B = LerMatriz("B.txt"); Console.WriteLine(NumeroDeOcorrencias(A, B)); } static int NumeroDeOcorrencias(int[,] matriz, int[,] padrão) { int N = matriz.GetLength(0), M = matriz.GetLength(1); int n = padrão.GetLength(0), m = padrão.GetLength(1); int contador = 0; /////////////////////////////////////////////////////// // // Escreva seu código aqui // /////////////////////////////////////////////////////// return contador; } static int[,] LerMatriz(string fileName) { FileStream f = new FileStream(fileName, FileMode.Open); StreamReader sr = new StreamReader(f); string[] tamanho = sr.ReadLine().Split(' '); int n = int.Parse(tamanho[0]); int m = int.Parse(tamanho[1]); int[,] ret = new int[n,m]; for(int i=0; i<n; ++i) { string linha = sr.ReadLine(); for (int j = 0; j < m; ++j) ret[i, j] = linha[j] == '0' ? 0 : 1; } sr.Close(); return ret; } static void CriaMatriz(string fileName, int n, int m) { Random r = new Random(); FileStream f = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(f); sw.Write($"{n} {m}\r\n"); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) sw.Write(r.Next(2) == 0 ? '0' : '1'); sw.Write("\r\n"); } sw.Close(); f.Close(); } } } </code>
  2. boa tarde podia me ajudar e quase igual a esta sua : 1 Uma imagem em preto e branco, de tamanho m x n, pode ser representada por uma matriz cujos elementos assumem valores no conjunto {0,1}. Dado um padrão representado por uma matriz 33 também assumindo valores em {0,1}, escreva uma função, ou trecho de código, que determine se o padrão existe ou não na imagem. (8 pontos) using System; using System.IO; namespace Testes { class Program { static void Main(string[] args) { CriaMatriz("A.txt", 200, 350); CriaMatriz("B.txt", 3, 4); int[,] A = LerMatriz("A.txt"); int[,] B = LerMatriz("B.txt"); Console.WriteLine(NumeroDeOcorrencias(A, B)); } static int NumeroDeOcorrencias(int[,] matriz, int[,] padrão) { int N = matriz.GetLength(0), M = matriz.GetLength(1); int n = padrão.GetLength(0), m = padrão.GetLength(1); int contador = 0; /////////////////////////////////////////////////////// // // Escreva seu código aqui // /////////////////////////////////////////////////////// return contador; } static int[,] LerMatriz(string fileName) { FileStream f = new FileStream(fileName, FileMode.Open); StreamReader sr = new StreamReader(f); string[] tamanho = sr.ReadLine().Split(' '); int n = int.Parse(tamanho[0]); int m = int.Parse(tamanho[1]); int[,] ret = new int[n,m]; for(int i=0; i<n; ++i) { string linha = sr.ReadLine(); for (int j = 0; j < m; ++j) ret[i, j] = linha[j] == '0' ? 0 : 1; } sr.Close(); return ret; } static void CriaMatriz(string fileName, int n, int m) { Random r = new Random(); FileStream f = new FileStream(fileName, FileMode.Create); StreamWriter sw = new StreamWriter(f); sw.Write($"{n} {m}\r\n"); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) sw.Write(r.Next(2) == 0 ? '0' : '1'); sw.Write("\r\n"); } sw.Close(); f.Close(); } } }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!