Cod sursa(job #3258300)

Utilizator teodoriftimeIftime Teodor teodoriftime Data 21 noiembrie 2024 19:54:07
Problema Bool Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");

int n,a[30],p;
char s[1000],c;
int expr();int termen();int factor();
int factor()
{   int f,ok=1;
    if(s[p]=='N' && s[p+1]=='O')
    {   p+=3;
        ok=1-ok;
        f=factor();
    }
    else
    {   if(s[p]=='('){p++;f=expr();p++;}
        else
        {   if(s[p]=='T' && s[p+1]=='R')
            {   p=p+4;
                f=1;
            }
            else if(s[p]=='F' && s[p+1]=='A')
            { p=p+5;
              f=0;
            }
            else
            { f=a[s[p]-'A'];
              p++;
            }
        }
    }
    if(ok)return f;
    else return 1-f;
}
int termen()
{ int t=factor();
  while(s[p]=='A' && s[p]=='N')
  { p=p+3;
    t=t&factor();
  }
  return t;
}
int expr()
{
    int e=termen();
    while(s[p]=='O' && s[p+1]=='R')
    { p+=2;
      e=e|termen();
    }
    return e;
}
int main()
{   cin.getline(s,1001);
    cin>>n;
    int j=0;
    for(int i=0;s[i];++i)if(s[i]!=' ')s[j++]=s[i];
    s[j]=NULL;
    for(int i=1;i<=n;i++)
    {   cin>>c;
        a[c-'A']=1-a[c-'A'];
        p=0;
        cout<<expr();
    }
    cout<<'\n';
    return 0;
}