Cod sursa(job #332584)

Utilizator cristi12345Balu Cristian cristi12345 Data 18 iulie 2009 20:29:04
Problema Bool Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 3.06 kb
var s:array[1..1000] of char;  
v:array['A'..'Z'] of 0..1;  
n,i,j:word;  
ca:char;  
f,g:text;  
function o(var x:word):byte;  
         forward;  
function p(var x:word):byte;  
         var a,d:0..1;  
         begin  
         if s[x]=' ' then  
            x:=x+1;  
         a:=o(x);  
         if s[x]=' ' then  
            x:=x+1;  
         while (s[x]='O') and (s[x+1]='R') do  
               begin  
               x:=x+2;  
               if s[x]=' ' then  
                  x:=x+1;  
               d:=o(x);  
               if a+d>0 then  
                  a:=1  
               else  
                   a:=0;  
               end;  
         p:=a;  
         end;  
function an(var x:word):byte;  
         forward;  
function o(var x:word):byte;  
         var b,e:0..1;  
         begin  
         b:=an(x);  
         if s[x]=' ' then  
            x:=x+1;  
         while (s[x]='A') and (s[x+1]='N') do  
               begin  
               x:=x+3;  
               if s[x]=' ' then  
                  x:=x+1;  
               e:=an(x);  
               if b+e=2 then  
                  b:=1  
               else  
                   b:=0;  
               end;  
         o:=b;  
         end;  
function an(var x:word):byte;  
         var c:0..1;  
         begin  
         if (s[x]='N') and (s[x+1]='O') then  
            begin  
            x:=x+3;  
            if s[x]=' ' then  
               x:=x+1;  
            c:=1-an(x);  
            end  
         else  
             if s[x]='(' then  
                begin  
                x:=x+1;  
                if s[x]=' ' then  
                   x:=x+1;  
                c:=p(x);  
                if s[x]=' ' then  
                   x:=x+1;  
                x:=x+1;  
                if s[x]=' ' then  
                   x:=x+1;  
                end  
             else  
                 if (s[x]='T') and (s[x+1]='R') then  
                    begin  
                    x:=x+4;  
                    if s[x]=' ' then  
                       x:=x+1;  
                    c:=1;  
                    end  
                 else  
                     if (s[x]='F') and (s[x+1]='A') then  
                        begin  
                        x:=x+5;  
                        if s[x]=' ' then  
                           x:=x+1;  
                        c:=0;  
                        end  
                     else  
                         begin  
                         c:=v[s[x]];  
                         x:=x+1;  
                         if s[x]=' ' then  
                            x:=x+1;  
                         end;  
         an:=c;  
         end;  
begin  
assign(f,'bool.in');  
assign(g,'bool.out');  
reset(f);rewrite(g);  
while not eoln(f) do  
      begin  
      i:=i+1;  
      read(f,s[i]);  
      end;  
readln(f);  
readln(f,n);  
for i:=1 to n do  
    begin  
    read(f,ca);  
    v[ca]:=1-v[ca];  
    j:=1;  
    write(g,p(j));  
    end;  
close(f);close(g);  
end.