Cod sursa(job #2068116)
Utilizator | Data | 17 noiembrie 2017 10:46:49 | |
---|---|---|---|
Problema | Subsir crescator maximal | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.64 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("sclm.in");
ofstream out("sclm.out");
int main()
{
int n,a[100];
in>>n;
for(int i=0;i<n;i++)
in>>a[i];
a[n]=32000;
int c[100];
int L=0, i ,j;
for( i=0;i<n;i++)
{
int nr=0;
for( j=i;j<n;j++ )
{
if(a[j]<=a[j+1])
nr++;
}
if(nr>L)
{
L=nr;
int l=0;
for(int j=i;j<n;j++)
{
if(a[j]<=a[j+1])
{c[l]=a[j];
l++;
}
}
}
nr=0;
}
out<<L;
out<<endl;
for(int i =0;i<L;i++)
out<<c[i]<<" ";
}