Cod sursa(job #2765668)

Utilizator BogdanNPPupeza Bogdan BogdanNP Data 29 iulie 2021 12:50:50
Problema Subsir crescator maximal Scor 0
Compilator c-64 Status done
Runda Arhiva educationala Marime 1.29 kb
#include <stdlib.h>
#include <stdio.h>

int n, poz, pozmax;
int a[100001];
int x, xmax;

int main()
{
    FILE* pf = fopen("scmax.in", "r");
    fscanf(pf, "%d", &n);
    x = 1;
    xmax = 1;

    for(int i = 0; i < n; ++i)
    {
        fscanf(pf, "%d", &(a[i]));
        printf("%d\n", x);
        if (x == 1)
        {
            ++x;
            poz = i;
        }
        else
        {
            if(a[i] == a[i - 1])
            {

                continue;
            }
            if(a[i] > a[i - 1])
            {
                ++x;
            }
            else
            {

                if(x > xmax)
                {
                    xmax = x;
                    pozmax = poz-1;
                    x = 1;
                }
            }
        }

    }
    fclose(pf);
    if(x > xmax)
    {
        xmax = x;
        pozmax = poz-1;
        x = 0;
    }
    pf = fopen("scmax.out", "w");
    fprintf(pf, "%d\n", xmax);
    while(xmax != 0 && pozmax <= n)
    {
        if(a[pozmax] == a[pozmax - 1])
        {
            pozmax++;
            continue;
        }
        else
        {
            fprintf(pf, "%d ", a[pozmax]);
        }
        xmax--;
        pozmax++;
    }
    fclose(pf);
    return 0;
}