Pagini recente » Cod sursa (job #1540255) | Cod sursa (job #568021) | Cod sursa (job #1215238) | Cod sursa (job #1317168) | Cod sursa (job #2362058)
#include <fstream>
using namespace std;
int n, c1, c2, i, k;
int st2[1001];
bool fr[40];
char s[1001], cuv[6], st1[1001], car, pr[300];
void operatie( char op){
if(op=='O'){
st2[c2]=!st2[c2];
c1--;
return;
}
if(op=='N'){
st2[c2-1]=st2[c2-1]&&st2[c2];
c2--;
c1--;
return;
}
st2[c2-1]=st2[c2-1]||st2[c2];
c2--;
c1--;
}
int evaluare ()
{
int i=0;
for (i=0;s[i]!=0;i++) {
if (s[i]>='A' && s[i]<='Z') {
int k=0;
while (s[i]>='A' && s[i]<='Z') {
cuv[k++]=s[i];
i++;
}
i--;
cuv[k]=0;
if (k==1) {
st2[++c2]=fr[cuv[0]-'A'];
}else
if (cuv[1]=='O')
st1[++c1]='O';
else if (cuv[0]=='T')
st2[++c2]=1;
else if (cuv[0]=='F')
st2[++c2]=0;
else {
while (c1>0 && pr[st1[c1]]>pr[cuv[1]])
operatie(st1[c1]);
c1++;
st1[c1]=cuv[1];
}
} else if (s[i]=='(')
st1[++c1]='(';
else
if (s[i]==')') {
while (st1[c1]!='(')
operatie(st1[c1]);
c1--;
}
}
while (c1>0)
operatie(st1[c1]);
return st2[1];
}
int main () {
ifstream fin ("bool.in");
ofstream fout ("bool.out");
fin.getline(s, 1001);
fin>>n;
pr['R']=1;//or
pr['N']=2;//and
pr['O']=3;//not
for (i=1;i<=n;i++) {
fin>>car;
fr[car-'A']=!fr[car-'A'];
c1=0;c2=0;
fout<<evaluare ();
}
return 0;
}