Cod sursa(job #15042)

Utilizator raula_sanChis Raoul raula_san Data 10 februarie 2007 16:24:14
Problema Subsir 2 Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<stdio.h>
#define dim 5001
using namespace std;

long x[dim], xx[dim];

int main() {
    FILE *f, *g;
    
    f = fopen("subsir2.in", "r");
    
    int N, i, j, poz, k = 0, cont = 1;

    long max;

    fscanf(f, "%d", &N);

    for(i=0; i<N; i++) fscanf(f, "%ld", &x[i]);

    fclose(f);

    xx[k++] = 1;

    for(i=0; i<(N-1); i=(poz-1)) {
	     max = 1000001;

	     for(j=(i+1); j<N; j++) {
			  if(x[j] > x[i] && x[j] < max) {
				  max = x[j];
		     		  poz = (j+1);
			  }
	     }

	     xx[k++] = poz;
	     cont ++;
    }
    g = fopen("subsir2.out", "w");

    fprintf(g, "%d\n", cont);

    for(i=0; i<cont; i++)
	     fprintf(g, "%ld ", xx[i]);

    fprintf(g, "\n");
    
    fclose(g);
    
    return 0;    
}