Cod sursa(job #798959)

Utilizator un_nenorocitChelcioiu Daniel un_nenorocit Data 17 octombrie 2012 17:21:05
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
# include <stdio.h>
# include <stdlib.h>
# include <iostream>

# define NMAX 100000

void seq (int *v, int n, int *max, int *pos) {
     int i;
     int best[n];
     *max = 0;
     *pos = 0;
     best[0] = 1;
   for (i = 1; i < n; i++){
       if (v[i] < v[i-1])
          best[i]=1;
          else {
          best[i] = best[i-1] + 1;
          if (*max < best[i]) {
           *max = best[i];
           *pos = i;
          }
          }
   }
   
     }

int main () {
   FILE *f, *g;
   int i, n, v[NMAX], max, pos;
   f = fopen ("scmax.in", "r");
   g = fopen ("scmax.out", "w");
   fscanf (f, "%d", &n);
   for (i = 0; i < n; i++){
    fscanf(f, "%d", &v[i]);
    }
     seq(v, n, &max, &pos);
     fprintf(g, "%d\n", max);
    for (i = 0 ; i < max; i++)
     fprintf (g, "%d ",v[pos-max+i+1]); 
return 0;
}