TOPIC

Presentation 5%, não consigo achar o erro.

lcampesatto0 asked 3 years ago

Já tentei todos os tipos de formatações

using System; using System.Globalization;

namespace Programas_Judge { class URI { static void Main(string[] args) { //string[] linha = Console.ReadLine().Split(' ');

        int val = Convert.ToInt32(Console.ReadLine());

        while(val != 0)
        {
            int com = 0, fim = val, pren = 1;
            int[,] mat = new int[val,val];
            int calc = val / 2, calc2 = val / 2 + 1;

            if(val % 2 == 0)
            {
                while(pren <= calc)
                {
                    for(int i = com; i < fim; i++)
                    {
                        for(int j = com; j < fim; j++)
                        {
                            mat[i,j] = pren;
                        }
                    }
                    com++;
                    fim--;
                    pren++;
                }
            }

            else
            {
                while(pren <= calc2)
                {
                    for(int i = com; i < fim; i++)
                    {
                        for(int j = com; j < fim; j++)
                        {
                            mat[i,j] = pren;
                        }
                    }
                    com++;
                    fim--;
                    pren++;
                }
            }

            for(int i = 0; i < val; i++)
            {
                for(int j = 0; j < val; j++)
                {
                    if(j < val-1)
                    {
                        Console.Write(String.Format("{0,4:0}", mat[i,j]));
                    }
                    else
                    {
                        Console.WriteLine(String.Format("{0,4:0}", mat[i,j]));
                    }
                }
            }
            Console.Write("\n");

            val = Convert.ToInt32(Console.ReadLine());
        }
    }
}

}

Remember not post solutions. Your post may be reviewed by our moderators.

  • Clayton22 replied 3 years ago

    Olá Lucas tudo bem Ao invés de "if (j < val - 1)" utilizei a condição abaixo:

    if (j == 0) {
      Console.Write(String.Format("{0,3}", M[i, j]));
    }
    else {
      Console.Write(String.Format("{0,4}", M[i, j]));
    }

    Como utilizei a estrutura "do { } while(N > 0);" antes de realizar a quebra de linha entre cada matriz inseri a condição abaixo, pois não pode haver quebra linha após o usuário digitar ZERO:

    if (N == 0) {
      break;
     }

    Meu código também só dava Presentation ERROR, depois dos ajustes acima foi aceito. Espero ter ajudado.