Cod sursa(job #940863)

Utilizator varga13VarGaz13 varga13 Data 17 aprilie 2013 11:59:23
Problema Perle Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <fstream>
using namespace std;

ifstream f("perle.in");
ofstream g("perle.out");
int n,m,aux[10005],B(int p),C(int p);
int main()
{

    f>>n;
    for(int i=0;i<n;i++)
    {
        f>>m;
        if(m==1)
        {
            f>>*aux;
           // g<<1;
            g<<"M";
        }
        else
        {
           for(int j=0;j<m;j++)
                f>>aux[j];

            if(*aux==2)
            {
                if(B(1))
                   // g<<1;
                    g<<"BB";
                else
                   // g<<0;
                    g<<"01";
            }
            else
            {
                if(C(0)) //g<<1;//
                g<<"C";
                else if (B(0)) //g<<1;
                g<<"B";
                else //g<<0;//
                g<<"02";
            }

        }
    g<<'\n';
    }

    f.close();
    g.close();
    return 0;
}

int B(int p)
{
if(p>=m-4) return 0;
if(aux[p]==2)
{
    return B(++p);
}
else if(aux[p]==1&&aux[p+2]==3)
{
    p+=4;
    return C(p);
}
return 0;
}


int C(int p)
{
if(p>=m) return 0;
if(aux[p]==2) return p+1;
else if(aux[p]==3) return C(B(p)+1);
else if(aux[p]==1&&aux[p+1]==2) return p+3;
return 0;
}