TOPIC

Wrong answer (20%)

Limao223 asked 3 years ago

Olá pessoal. Estou fazendo o exercicio 1180 e é retornado o erro Wrong answer (20%), mas não consigo achar onde esta o erro

Question solved. Code removed. Bom, porém fiz o mesmo em C e foi aceita

Question solved. Code removed. Qual poderia ser o erro?

This topic was solved and cannot recieve new replies.

  • feodorv replied 3 years ago

    Why this condition?

            if(vetor[i] < vetor[i + 1]){

    You should only compare menor and vetor[ i ] for each possible i.

    About the code.

        int chaveMenor, menor, posicao;

    menor here is not initialized and can contain any garbage value. You can init it by INT_MAX from < limits.h>. Or you can init it with first array element and then cycle from 1 (not from 0).

        for(i=0; i<n; i++){
            if(vetor[i] < vetor[i + 1]){

    When i becomes n-1 you have vetor[ n ] which is out of array bounds.