Pagini recente » Cod sursa (job #2334199) | Cod sursa (job #3168569) | Cod sursa (job #2456712) | Cod sursa (job #2840095) | Cod sursa (job #1322680)
// proj2.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *file = NULL;
long *vector = NULL;
long *maxv = NULL;
long *testv = NULL;
long N = 0;
file = fopen("scmax.in", "rt");
fscanf(file, "%ld", &N);
N = N + 1;
vector = (long *)malloc(N * sizeof(long));
maxv = (long *)malloc(N * sizeof(long));
testv = (long *)malloc(N * sizeof(long));
for (int i = 0; i < N; i++) {
maxv[i] = 0;
testv[i] = 0;
}
for (int i = 0; i < N; i++) {
fscanf(file, "%ld", &vector[i]);
}
fclose(file);
int j = 0, k = 0;
bool active = false;
for (int i = 0; i < N; i++) {
if (vector[i] >= testv[j]) {
j++;
testv[j] = vector[i];
active = true;
} else {
active = false;
if (j > k) {
for (int _i = 0; _i < j; _i++) {
maxv[_i] = testv[_i];
testv[_i] = 0;
}
}
k = j;
j = 0;
}
}
file = fopen("scmax.out", "wt");
fprintf(file, "%d\r\n", k);
for (int i = 0; i < k; i++) {
fprintf(file, "%ld ", maxv[i]);
}
fclose(file);
return 0;
}