Pagini recente » Profil dornescuvlad | Cod sursa (job #3208232) | Istoria paginii utilizator/elena_florina_marinas | Cod sursa (job #2549568) | Cod sursa (job #798964)
Cod sursa(job #798964)
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
int scsm(int *v, int n, int *poz)
{
int i, max, p, best[MAX];
best[0] = 1;
for (p = -1, max = 0, i = 1; i < n; ++i)
{ if (v[i] < v[i-1])
best[i] = 1;
else if (v[i] == v[i-1])
{
best[i] = best[i-1];
if (max < best[i])
{ max = best[i];
p = i;
}
}
else
{ best[i] = best[i-1] + 1;
if (max < best[i])
{ max = best[i];
p = i;
}
}
}
*poz = p;
return max;
}
int main()
{
FILE *f, *g;
int n, v[MAX], i, max, p;
f = fopen("scmax.in", "r");
fscanf(f, "%i", &n);
for (i = 0; i < n; ++i)
fscanf(f, "%i", v+i);
// for (i = 0; i < n; i++)
// printf("v[%i] = %i\n", i, v[i]);
g = fopen("scmax.out", "w");
max = scsm(v, n, &p);
fprintf(g, "%i\n", max);
for (i = p - max + 1; max > 0; i++, max--)
fprintf(g, "%i ", v[i]);
return 0;
}