Cod sursa(job #253703)

Utilizator ErgoVicol Sergiu Constantin Ergo Data 6 februarie 2009 11:30:58
Problema Episoade Scor 20
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 1 Marime 1.4 kb
#include <fstream>
#include <string.h>
using namespace std;

ifstream fin("episoade.in");
ofstream fout("episoade.out");

#define NMAX 102
#define LMAX 1002

struct episod
{
        int p,n,g;
}   ;
episod A[NMAX];
int G[LMAX],B[NMAX];
char E[LMAX];
int L,T,N,pos;

void expresie();

int main()
{
        int ip,i,ok;
        fin.getline(E,LMAX);
        L=strlen(E);
        fin>>T>>N;
        pos=0;
        expresie();


        for (ip=1;ip<=T;ip++)
        {
                //Verificare
                B[0]=-1;
                for (i=1,ok=1;i<=N;i++)
                {
                        fin>>B[i];
                        if (A[B[i]].n!=1&&B[i-1]!=A[B[i]].p) ok=0;
                }
                if (ok) fout<<"1\n";
                else fout<<"0\n";
        }

        
        fout.close();
        return 0;
        
}

void expresie()
{
        A[(int)E[pos]-48].p=-1;
        A[(int)E[pos]-48].n=1;
        pos++;
        while (pos<=L)
        {
                if (E[pos]=='>')
                {
                        pos++;
                        A[(int)E[pos]-48].n=A[(int)E[pos-2]-48].n+1;
                        A[(int)E[pos]-48].p=(int)E[pos-2]-48;
                } else
                if (E[pos]=='#')
                {
                        pos++;
                        A[(int)E[pos]-48].n=1;
                        A[(int)E[pos]-48].p=-1;
                }
                pos++;
        }
}