Cod sursa(job #2174398)

Utilizator PredaBossPreda Andrei PredaBoss Data 16 martie 2018 11:51:52
Problema Perle Scor 100
Compilator cpp Status done
Runda ne-auzim Marime 2.35 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int v[100000],n,l;
vector<string>a,b,c;
bool try_this(string str,int pos)
{
    if(str[0]-'0'==v[pos])
    {
        str.erase(0,1);
        if(str.size()>l-pos)
            return 0;
        pos++;
        while(str.size()>1 && isdigit(str[0]))
        {
            pos++;
            if(str[0]-'0'!=v[pos-1])
            return 0;
            str.erase(0,1);
        }
        if(str.empty())
        {
            if(l>=pos)
            return 0;
            return 1;
        }
        bool k=0;
        if(str[0]=='a')
        {
            str.erase(0,1);
            for(int j=0;j<a.size();j++)
            {
                k=try_this(a[j]+str,pos);
                if(k)
                    return 1;
            }
            return 0;
        }
        if(str[0]=='b')
        {
            str.erase(0,1);
            for(int j=0;j<b.size();j++)
            {
                k=try_this(b[j]+str,pos);
                if(k)
                    return 1;
            }
            return 0;
        }
            str.erase(0,1);
            for(int j=0;j<c.size();j++)
            {
                k=try_this(c[j]+str,pos);
                if(k)
                    return 1;
            }
            return 0;
    }
    return 0;
}
void cetire()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>l;
        for(int j=1;j<=l;j++)
            fin>>v[j];
            bool k=0;
        for(int j=0;j<a.size();j++)
        {
            k=try_this(a[j],1);
            if(k)
                break;
        }
        if(!k)
        {
            for(int j=0;j<b.size();j++)
            {
                k=try_this(b[j],1);
                if(k)
                    break;
            }
        }
        if(!k)
        {
            for(int j=0;j<c.size();j++)
            {
                k=try_this(c[j],1);
                if(k)
                    break;
            }
        }
        fout<<k<<"\n";
    }
}
int main()
{
    a.push_back("1");
     a.push_back("2");
      a.push_back("3");
       b.push_back("2b");
        b.push_back("1a3ac");
         c.push_back("2");
          c.push_back("3bc");
           c.push_back("12a");
    cetire();
    return 0;
}