Cod sursa(job #1356301)

Utilizator HunMakerFazekas Hunor HunMaker Data 23 februarie 2015 12:50:38
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n,i,j,x,max;

    ifstream file1;
    file1.open("In.txt");
    file1 >> n;
    int V[n],W[n];

    for( i=0 ; i<n ; i++ )
    {
     file1 >> x;
     V[i]=x;
     W[i]=1;
    }
    file1.close();

    for( i=0 ; i<n ; i++ )
    {
     for( j=0 ; j<i ; j++ )
     {
      if( V[i]>V[j] && W[j]==W[i])
      {
       W[i]++;
      }
     }
    }

    max=W[0];
    for( i=1 ; i<n ; i++ )
    {
     if(W[i] > max)
     max=W[i];
     j=i;
    }
    ofstream file2;
    file2.open("Out.txt");
    file2 << max << '\n';
    int N[max];
    x=0;

    for( i=j ; i>=0 ; i-- )
    {
    if(max==W[i])
     {
      N[x]=V[i];
      x++;
      max--;
      j--;
     }
    }
    for( i=(x-1) ; i>=0 ; i-- )
    {
     file2 << N[i] <<" ";
    }

    file2.close();

    return 0;
}