Pagini recente » Cod sursa (job #2762336) | Cod sursa (job #493112) | Cod sursa (job #2250559) | Cod sursa (job #2409894) | Cod sursa (job #2484362)
#include <iostream>
#include <fstream>
#include <map>
#include <string>
using namespace std;
ifstream f("bool.in");
ofstream g("bool.out");
map <char,bool> m;
string s="";
int n;
string reconstruct(char *p)
{
string s="";
while(*p!='\00')
{
if(*p==' ')
{++p;
continue;}
if(*p>='A' && *p<='Z')
{
if(*(p+1)==' ' || *(p+1)==')' || *(p+1)=='\00')
{
m[*p]=0;
s+=*p;
++p;
}
else
{
if(*p=='A')
s+='&',p+=4;
else if(*p=='O')
s+='|',p+=3;
else if(*p=='N')
s+='~',p+=4;
else if(*p=='T')
s+='1',p+=5;
else if(*p=='F')
s+='0',p+=6;
}
}
else
{
s+=*p;
++p;
}
}
return s;
}
bool eval(int &i),term(int &i);
bool eval(int &i)
{
bool t=term(i);
while(i<n && s[i]!=')')
{
bool x=term(++i);
t|=x;
}
return t;
}
bool term(int &i)
{
bool t=0;
if(s[i]=='(')
t=eval(++i);
else
if(s[i]=='~')
t=~m[s[++i]],++i;
else
t=m[s[i++]];
while(s[i]=='&')
{
bool x=term(++i);
t&=x;
}
return t;
}
int main()
{
char c[1001];
f.getline(c,1001);
s=reconstruct(c);
cout<<s<<'\n';
n=s.size();
int nr;
f>>nr;
while(nr--)
{
char q;
f>>q;
m[q]=!m[q];
int i=0;
g<<eval(i);
}
return 0;
}