Cod sursa(job #1086704)

Utilizator hi5allSerban Mihai Ionescu hi5all Data 18 ianuarie 2014 14:28:19
Problema Episoade Scor 100
Compilator cpp Status done
Runda game01 Marime 1.47 kb
//horatiu11
# include <cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int ok,poz,x,i,t,n,a[110];
char s[1010];
inline pair<int,int> eval(int l)
{
    if(l==0)
    {
        vector< pair<int,int> >v;
        v.push_back(eval(1));
        while(s[poz]=='#')
        {
            ++poz;
            v.push_back(eval(1));
        }
        sort(v.begin(),v.end());
        pair <int,int> x;
        x=v[0];
        for(unsigned int i=1;i<v.size();++i)
        {
            if(v[i-1].second+1!=v[i].first)ok=0;
            else x.second=v[i].second;
        }
        return x;
    }
    if(l==1)
    {
        pair <int,int>x,y;
        x=eval(2);
        while(s[poz]=='>')
        {
            ++poz;
            y=eval(2);
            if(x.second+1!=y.first)ok=0;
            x.second=y.second;
        }
        return x;
    }
    if(s[poz]=='(')
    {
       ++poz;
       pair<int,int> x=eval(0);
       ++poz;
       return x;
    }
    int x=0;
    while(s[poz]>='0'&&s[poz]<='9')
        x=x*10+s[poz]-'0',++poz;
    return make_pair(a[x],a[x]);
}
int main()
{
    int i;
    freopen("episoade.in","r",stdin);
    freopen("episoade.out","w",stdout);
    gets(s);
    scanf("%d%d",&t,&n);
    while(t)
    {
        for(i=1;i<=n;++i)
        {
            scanf("%d",&x);
            a[x]=i;
        }
        poz=0;ok=1;
        eval(0);
        printf("%d\n",ok);
        --t;
    }
    return 0;
}