TOPIC

Time limit exceeded - me ajuda.

umsaldanha asked 6 years ago

Ta rodando mas acho que esta lento, nao sei bem como resolver.. Ajuda aeh..

Está rodando bem o codigo aqui no meu pc.

#include <stdio.h>
int ler_vetor(int A[], int n){
    int i;

    for(i = 0; i < n; ++i){
        scanf("%d", &A[i]);
    }
    return 0;
}
int ordenar_vetor(int A[], int n){
    int aux = 0;
    int i, j;
    for (i = 0; i < n; ++i)
    {
        for (j = 0; j < n-1; ++j)
        {
            if(A[j] > A[j+1]){
                aux = A[j+1];
                A[j+1] = A[j];
                A[j] = aux;
            }
        }
    }
    return 0;
}
int verificar_quant_elementos_distintos(int A[], int n){
    int value = 1;
    int i;
    for (i = 0; i < (n-1); ++i)
    {
        if(i <= (n-1) && A[i] != A[i+1]){
            ++value;
        }
    }
    return value;
}

int main(){
    int T, N, n;

    scanf("%d", &T);

    while(T-- > 0){
        scanf("%d", &N);
        int carneirinhos[N];
        ler_vetor(carneirinhos, N);
        ordenar_vetor(carneirinhos, N);
        printf("%d\n", verificar_quant_elementos_distintos(carneirinhos, N));
    }
    return 0;
}

This topic has not been answered yet. Be the first!

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