Cod sursa(job #1209737)

Utilizator GligaEugenConstantinGliga Eugen GligaEugenConstantin Data 18 iulie 2014 14:13:31
Problema Subsir crescator maximal Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 2.05 kb
#include <stdlib.h>
#include <stdio.h>
using namespace std;


//I'll retain into an array only the ascending subarrays from the given input

int main ()
{
    int k;
    int i;
    int nrValues;
    int nrElements;
    int nr1;
    int minus;
    int auxStartIndex;
    auxStartIndex = 0;
    int startIndex;//the index from wich the longest subarray starts
    startIndex = 0;
    int maxLength;
    int auxMaxLength;
    int maxAscendingSubarray[100003];// can be bigger than 1000
    FILE *infile;
    FILE *outfile;
    auxMaxLength = -1;
    maxLength = 1;
   
    infile = fopen ("scmax.in","r");
    if (infile != NULL)
    {
        if(fscanf(infile, "%d", &nrValues));
        for( i =0; i< nrValues; i++)
        {
            if(fscanf(infile, "%d", &nr1));
            maxAscendingSubarray[i] = nr1;
        }
        fclose(infile);
    }

    i = 0;
    while(i <  nrValues - 1)
    {
        if(maxAscendingSubarray[i]< maxAscendingSubarray[i + 1])
        {
            startIndex = i;
            while(maxAscendingSubarray[i] < maxAscendingSubarray[i + 1])
            {
                maxLength++;
                i++;
            }
            if( maxLength > auxMaxLength )
            {
                auxMaxLength = maxLength;
                auxStartIndex = startIndex;
            }
            maxLength = 1;
        }
        else 
        {
            i++;
        }
    }
    maxLength = auxMaxLength;

    minus = 0;
    k = startIndex;
    startIndex = auxStartIndex;
    nrElements = startIndex + maxLength;
    
    
    outfile = fopen ("scmax.out","w");
    if (outfile != NULL)
    {
        fprintf(outfile, "%d\n",maxLength);
        k = startIndex;
        
        while
       ( k < nrElements )
        {
            //if( maxAscendingSubarray[k] != maxAscendingSubarray[k+1] ) 
            {
                fprintf(outfile, "%d ", maxAscendingSubarray[k]);
            }
             
        k++;
        }
        fclose(outfile);
    }
    
	
	return 0;
}