Advertisement
rdsedmundo

3.cs

Apr 20th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. public class Exercicio3
  4. {
  5.     public static void Main()
  6.     {
  7.         int n = 61;
  8.        
  9.         char[] celula = new char[n];
  10.        
  11.         for (int i = 0; i < n; i++)
  12.             celula[i] = ' ';
  13.        
  14.         /* 8 = celúla preta, espaço = célula branca */
  15.         celula[30] = '8';
  16.        
  17.         char[] novaCelula = new char[n];
  18.        
  19.         for (int i = 0; i < n; i++)
  20.             novaCelula[i] = ' ';
  21.        
  22.         int contador = 0;
  23.         /* repete 30 vezes o procedimento */
  24.         while (contador < 30) {
  25.             for (int i = 1; i < n - 1; i++) {
  26.                 /* verifica as regras */
  27.                 if (celula[i] == ' ' && celula[i - 1] == ' ' && celula[i + 1] == ' ')
  28.                     novaCelula[i] = ' ';
  29.                 else if (celula[i] == '8' && celula[i - 1] == '8' && celula[i + 1] == ' ')
  30.                     novaCelula[i] = ' ';
  31.                 else
  32.                     novaCelula[i] = '8';
  33.             }
  34.            
  35.             /* imprime o resultado atual */
  36.             Console.WriteLine(new string(novaCelula));
  37.             /* copia o novo array para o inicial */
  38.             novaCelula.CopyTo(celula, 0);
  39.             contador++;
  40.         }
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement