Cod sursa(job #3250869)

Utilizator andrei1232008nicolae andrei andrei1232008 Data 23 octombrie 2024 22:06:05
Problema Bool Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.75 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
bool nu();
bool si();
bool sau();
bool fact();
void debut();
int i,n,par,lg,lg2;
char s[1500],c[1500],l[1000];
unordered_map <int,bool> v;
int main()
{
    fin.getline(s,1400);
    lg=strlen(s);
    debut();
    lg=lg2;
    fin>>n;
    for(i=1;i<=n;i++)
    {fin>>l[i];v[(int)l[i]]=0;}
    for(par=1;par<=n;par++)
    {
        i=0;
        v[(int)l[par]]=1-v[(int)l[par]];
        fout<<sau();
    }
    return 0;
}
void debut()
{
    for(i=0;i<lg;i++)
    {
        if(i+2<lg&&s[i]=='A'&&s[i+1]=='N'&&s[i+2]=='D')
            c[lg2++]='&',i+=2;
        else if(i+2<lg&&s[i]=='N'&&s[i+1]=='O'&&s[i+2]=='T')
        c[lg2++]='!',i+=2;
        else if(i+1<lg&&s[i]=='O'&&s[i+1]=='R')
        c[lg2++]='|',i++;
        else if(i+3<lg&&s[i]=='T'&&s[i+1]=='R'&&s[i+2]=='U'&&s[i+3]=='E')
        c[lg2++]='1',i+=3;
        else if(i+4<lg&&s[i]=='F'&&s[i+1]=='A'&&s[i+2]=='L'&&s[i+3]=='S'&&s[i+4]=='E')
        c[lg2++]='0',i+=4;
        else c[lg2++]=s[i];
    }
}
bool sau()
{
    bool x=si();
    while(i<lg&&c[i]=='|')
    {
        i++;
        x|=si();
    }
    return x;
}
bool si()
{
    bool x=nu();
    while(i<lg&&c[i]=='&')
    {
        i++;
        x&=nu();
    }
    return x;
}
bool nu()
{
    if(c[i]=='!')
    {
        while(i<lg&&c[i]=='!')
        {
            i++;
            return 1-nu();
        }
    }
    else return fact();
}
bool fact()
{
    bool x=0;
    if(c[i]=='(')
    {
        i++;
        x=sau();
        i++;
    }
    else
    {
        if(isdigit(c[i]))x=c[i]-'0';
        else if(c[i]>='A'&&c[i]<='Z')x=v[(int)c[i]];
        i++;
    }
    return x;
}