Pagini recente » Cod sursa (job #2939290) | Istoria paginii runda/ampulamare/clasament | Cod sursa (job #560498) | Cod sursa (job #1481223) | Cod sursa (job #2540269)
#include <bits/stdc++.h>
#define N 1005
using namespace std;
ifstream fin ("bool.in");
ofstream fout ("bool.out");
char s[N];
char t[N];
bool f[26];
int i;
int n;
char mod[N];
bool Expresie();
bool Termen1(); /// ||
bool Termen2(); /// &&
bool Factor(); /// !
void Codificare();
void Rezolva()
{
Codificare();
int k;
for (k=0; k<n; ++k)
{
f[mod[k]-'A']=!f[mod[k]-'A'];
fout<<Expresie();
}
fout<<'\n';
fout.close();
}
int main()
{
fin.getline(s, N);
fin>>n;
fin>>mod;
fin.close();
Rezolva();
return 0;
}
void Codificare()
{
int k;
int m=0;
for (k=0; s[k]; ++k)
if (s[k]==' ') ;
else if (s[k]=='(' || s[k]==')') t[m++]=s[k];
else if (s[k]=='A' && s[k+1]=='N' && s[k+2]=='D') t[m++]='&', k+=2;
else if (s[k]=='O' && s[k+1]=='R') t[m++]='|', k++;
else if (s[k]=='N' && s[k+1]=='O' && s[k+2]=='T') t[m++]='!', k+=2;
else if (s[k]=='T' && s[k+1]=='R' && s[k+2]=='U' && s[k+3]=='E') t[m++]='1', k+=3;
else if (s[k]=='F' && s[k+1]=='A' && s[k+2]=='L' && s[k+3]=='S' && s[k+4]=='E') t[m++]='0', k+=4;
else t[m++]=s[k];
}
bool Expresie()
{
bool val=Termen1(); /// se evalueaza &&
while(t[i]=='|')
if(t[i]=='|') ++i,val=val || Termen1();
return val;
}
bool Termen1()
{
bool val=Termen2(); /// se evalueaza !
while(t[i]=='&')
if(t[i]=='&') ++i,val=val && Termen2();
return val;
}
bool Termen2()
{
bool val=Factor();
while(t[i]=='!')
if(t[i]=='!') ++i, val=!Factor();
return val;
}
bool Factor()
{
bool val=0;
if(t[i]=='(')
{
++i;
val=Expresie();
++i;
return val;
}
if(t[i]>='A' && t[i]<='Z') return f[t[i]-'A'];
else if(t[i]=='1') return 1;
else if(t[i]=='0') return 0;
return val;
}