Pagini recente » Cod sursa (job #3353458) | Cod sursa (job #3322795) | Cod sursa (job #3348713) | Cod sursa (job #495803) | Cod sursa (job #3311541)
//
// main.cpp
// Bool
//
// Created by Andrada Minca on 23.09.2025.
//
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("bool.in");
ofstream cout("bool.out");
int ind=0;
char s[1005];
vector<bool> state(27,false);
bool expresie();
bool factor();
bool termen();
bool numar();
bool altcv();
bool tf();
bool expresie()
{
if(s[ind]==' ')ind++;
bool ans=termen();
while(s[ind]=='O'&&s[ind+1]=='R')
{
ind+=2;
ans|=termen();
}
return ans;
}
bool termen()
{
if(s[ind]==' ')ind++;
bool ans=factor();
while(s[ind]=='A'&&s[ind+1]=='N'&&s[ind+2]=='D')
{
ind+=3;
ans&=factor();
}
return ans;
}
bool factor()
{
if(s[ind]==' ')ind++;
bool ans=altcv();
while(s[ind]=='N'&&s[ind+1]=='O'&&s[ind+2]=='T')
{
ind+=3;
ans=!altcv();
}
return ans;
}
bool altcv()
{
if(s[ind]==' ')ind++;
bool ans=0;
if(s[ind]=='(')
{
ind++;
ans=expresie();
ind++;
}
else if(s[ind+1]>'Z'||s[ind+1]<'A')
{
ans=numar();
ind++;
}
else ans=tf();
return ans;
}
bool tf()
{
if(s[ind]=='T')
{
ind+=4;
return true;
}
else if(s[ind]=='F')
{
ind+=5;
return false;
}
return false;
}
bool numar()
{
return state[s[ind]-'A'];
}
int main()
{
int n;
cin.getline(s,1005);
cin>>n;
for(int i=0;i<n;i++)
{
char x;
cin>>x;
state[x-'A']=!state[x-'A'];
cout<<expresie();
ind=0;
}
return 0;
}