Pagini recente » Cod sursa (job #60638) | Cod sursa (job #2186250) | Cod sursa (job #722294) | Cod sursa (job #738222) | Cod sursa (job #1831729)
#include <fstream>
#include <string>
#include <bitset>
std::fstream f("bool.in",std::ios::in);
std::ofstream g("bool.out");
std::string st;
int index = 0;
std::string update,line;
std::bitset<33>letters;
bool solve();
bool sn();
bool tn();
int main()
{
int nr,i,it=0,len;
bool ok;
char c,t;
std::getline(f,line);
len = line.length();
while(it < len)
{
while(line[it] == ' ')++it;
i = 0;
t = line[it];
while(line[it]>='A' && line[it]<='Z')
{
++it;
++i;
}
if(i==0)
{
st.push_back(line[it]);
++it;
}
else if(i==1)st.push_back(t);
else if(i==2)st.push_back('|');
else if(i==3 && t == 'N')st.push_back('!');
else if(i==3)st.push_back('&');
else if(i==4)st.push_back('1');
else if(i==5)st.push_back('0');
}
f>>nr>>update;
for(int i = 0;i<nr;++i)
{
letters.flip(update[i]-'A');
g<<solve();
index = 0;
}
return 0;
}
bool solve()
{
bool g = sn();
while(st[index] == '|')
{
++index;
g = g|sn();
}
return g;
}
bool sn()
{
bool g = tn();
while(st[index]=='&')
{
++index;
g = g&tn();
}
return g;
}
bool tn()
{
bool g;
if(st[index]== '(')
{
++index;
g = solve();
++index;
}
else
{
if(st[index]>='A' && st[index]<='Z')
{
g = letters[st[index]-'A'];
++index;
}
else if(st[index]=='1')
{
g = 1;
++index;
}
else if(st[index]=='0')
{
g = 0;
++index;
}
else if(st[index]=='!')
{
++index;
g = !tn();
}
}
return g;
}