Error when displaying results - URI 1566 [closed]

1

I have made a request in the URI problem 1566 statement, but it is giving presentation error, and I do not know how to fix it.

Here is my code:

#include <stdio.h>
#include <stdlib.h>

int ordena(const void *a, const void *b);

int main(int argc, char** argv)
{
  int teste, num;
  scanf("%d", &teste);
  for(int i = 0; i < teste; i++)
  {
     scanf("%d", &num);
     int vetor[num];
     for(int j = 0; j < num; j++)
     {
        scanf("%d", &vetor[j]);
     }
     qsort(vetor, num, sizeof(int), ordena);
     for(int j = 0; j < num; j++)
     {
        printf("%d ", vetor[j]);
     }
     printf("\n");
}
  return 0;
}

int ordena(const void *a, const void *b)
{

   if(*(int*)a == *(int*)b)
    return 0;
   else if(*(int*)a < * (int*)b)
    return -1;
   else
    return 1;
}
    
asked by anonymous 20.02.2018 / 02:25

1 answer

2

I think the problem is here:

       printf("%d ", vetor[j]);

This space at the end will mess up the automatic checking of code output. Try to do this:

       if (z != 0) printf(" ");
       printf("%d", vetor[j]);

With this, you will have the spaces before the number, only if it is not the first one, which should correct this problem.

Maybe printf("\n"); might give a similar problem as well. The solution would also be to put a if on it.

    
20.02.2018 / 02:50