• [^] # Re: Pas bien intéressant...

    Posté par . En réponse au message exercices donnés au codinggame n°2. Évalué à 2. Dernière modification le 30 octobre 2012 à 19:31.

    Mon code en C qui marche avec les séquences précédentes (et leurs tests):

    int main()
    {
     int n1 = -1; unsigned int n2 = 2e31+1;
     int pot_n1 = -1, distance_max = 1;
     int n;
     scanf("%d", &n);
     int x;
     for(int i=0; i<n; i++)
     {
     scanf("%d",&x);
     if(x > n1 && x > pot_n1)
     pot_n1 = x;
     else if(x < n2)
     {
     n2 = x;
     distance_max = n2 - n1;
     }
     if(x-pot_n1 < distance_max)
     {
     n1 = pot_n1;
     pot_n1 = -1;
     n2 = x;
     distance_max = n2-n1;
     }
     }
     if(n2>n1)
     printf("0\n");
     else
     printf("%d\n",distance_max);
     return 0;
    }