Cod sursa(job #2074434)

Utilizator AlexandruabcdeDobleaga Alexandru Alexandruabcde Data 24 noiembrie 2017 16:48:49
Problema Kdrum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.91 kb
#include <fstream>

using namespace std;
ifstream f ("cuburi.in");
ofstream g ("cuburi.out");
int n,i,x,z=0,COADA[10],p,y,k,cx,vf,nre,poznen,j;
int main()
{
    f>>n>>k;
    while (z*6<n)
    {
        p++;
        z=z+p*p;
    }
    g<<p-1<<'\n';
    z=0;
    for (i=1;i<=k;i++)
    {
        z=z+i*i;
    }
    for (i=1; i<=z*6; i++)
    {
        vf=0;
        f>>x;
        p=1;
        cx=x;
        while (cx!=0)
        {
            p=p*10;
            cx=cx/10;
        }
        p=p/10;
        COADA[1]=x/p%10;
        p=p/10;
        cx=x;
        nre=0;
        vf=1;
        poznen=1;
        while (p>0)
        {
            y=cx/p%10;
            if (y==0)
            {
                vf++;
                COADA[vf]=0;

                while (COADA[vf-1]!=0 && vf-1>1 && nre<3)
                {
                    vf--;
                    nre++;
                }
                COADA[vf]=0;
            }
            else if (nre==3)
            {
                vf++;
                COADA[vf]=y;
            }
            else
            {
                while (COADA[vf]>y && vf!=0 && nre<3)
                {
                    vf--;
                    nre++;
                }
                vf++;
                COADA[vf]=y;
                poznen=vf-1;
                while (poznen!=0 && COADA[poznen]==0 && nre<3)
                {
                    poznen--;
                }
                if (vf-poznen<=3-nre && vf-poznen>1 && COADA[vf]<COADA[poznen])
                {
                    COADA[poznen]=COADA[vf];
                    nre=nre + vf-poznen;
                    vf=poznen;
                }
            }
            p=p/10;
        }
        for (j=1;j<=vf-(3-nre);j++)
        {
            g<<COADA[j];
        }
        g<<" ";
        for (j=1;j<=vf;j++)
            COADA[j]=0;
    }
    return 0;
}