Pagini recente » Cod sursa (job #192749) | Cod sursa (job #1518081) | Cod sursa (job #1898174) | Cod sursa (job #2243925) | Cod sursa (job #2949642)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("bool.in");
ofstream fout("bool.out");
int n,i;
char s[1005],mods[104];
bool v[27];
bool verif_litera()
{
int cnt=0;
while(s[i+cnt]==' ') i++;
if('A'<=s[i+cnt] && s[i+cnt]<='Z' && (s[i+cnt+1]<'A' || s[i+cnt+1]>'Z') ) return true;
return false;
}
bool str_match(string str)
{
int cnt=0;
while(s[i+cnt]==' ') i++;
while(s[i+cnt]==str[cnt] && cnt<str.size()) cnt++;
if(cnt==str.size()) return true;
return false;
}
bool eval_exp();
bool term_or();
bool term_and();
bool term_not();
bool eval_exp()
{
while(s[i]==' ') i++;
bool rasp = term_or();
while(str_match("OR"))
{
i+=2;
rasp = rasp | term_or();
}
return rasp;
}
bool term_or()
{
while(s[i]==' ') i++;
bool rasp = term_and();
while(str_match("AND"))
{
i+=3;
rasp=rasp & term_and();
}
return rasp;
}
bool term_and()
{
while(s[i]==' ') i++;
bool rasp=0;
if(str_match("NOT"))
{
i+=3;
rasp = !term_not();
}
else rasp = term_not();
return rasp;
}
bool term_not()
{
bool rasp=0;
while(s[i]==' ') i++;
if(s[i]=='(')
{
i++;
rasp=eval_exp();
while(s[i]==' ') i++;
i++;
}
else if(verif_litera())
{
rasp=v[s[i]-'A'];
i++;
}
else if(str_match("TRUE"))
{
rasp=true;
i+=4;
}
else if(str_match("FALSE"))
{
rasp=false;
i+=5;
}
return rasp;
}
int main()
{
fin.getline(s,1004);
fin>>n;
fin>>mods;
for(int it=0; it<n; it++)
{
v[mods[it]-'A'] = !v[mods[it]-'A'];
i=0;
fout<<eval_exp();
}
return 0;
}