# TOPIC

Tempo limite excedido Como resolver

#### Diogo Alves asked 3 years ago

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

int compara(const void * a, const void * b);
int veri(int aux[], int indice[], int teste);

int main(int argc, char** argv)
{
int teste, vetor[100000], i, aux[100000], indice[100000], cont, j;
scanf("%d", &teste);
while(teste != 0)
{
cont = 0;
for(i = 0; i < teste; i++)
{
scanf("%d", &vetor[i]);
aux[i] = vetor[i];
}
qsort(vetor, teste, sizeof(int), compara);
for(i = 0; i < teste; i++)
{
for(j = 0; j < teste; j++)
{
if(vetor[i] == aux[j])
{
indice[cont++] = j + 1;
}
}
}
if(teste == veri(aux, indice, teste))
{
puts("ambiguous");
}
else
{
puts("not ambiguous");
}
scanf("%d", &teste);
}
return 0;
}

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

if(*(int*)a == *(int*)b)
return 0;
else if(*(int*)a < * (int*)b)
return -1;
else
return 1;
}
int veri(int aux[], int indice[], int teste)
{
int cont = 0, i, j;
for(i = 0; i < teste; i++)
{
for(j = 0; j < teste; j++)
{
if(indice[i] == aux[j])
{
cont++;
}
}
}
return cont;
}
``````

Como resolver

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

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