Pagini recente » Cod sursa (job #1112361) | Cod sursa (job #760805) | Cod sursa (job #822996) | Cod sursa (job #2695818) | Cod sursa (job #2320274)
#include <fstream>
#include <cstring>
using namespace std;
int const NM = 1001;
char init [NM] , s [NM];
bool v [1 + 'Z'];
ifstream f ("bool.in");
ofstream g ("bool.out");
bool exp ();
bool term ();
bool fact ();
int p;
bool exp (){
bool sum = term ();
while (s [p] == 'o'){
++ p;
sum = sum | term ();
}
return sum;
}
bool term (){
bool prod = fact ();
while (s [p] == 'a'){
if (s [p] == 'a'){
++ p;
prod = prod & fact ();
}
}
return prod;
}
bool fact (){
bool x = true , val = false;
while (s [p] == 'n'){
x = false;
++ p;
}
int pr = 0;
if (s [p] == '('){
while (s [p] == '(')
++ p , ++ pr;
val = exp ();
p += pr;
return x ? val : ! val;
}
if (isdigit (s [p]))
val = (bool)(int)(s [p] - '0') , ++ p;
if (s [p] <= 'Z' && s [p] >= 'A')
val = v [s [p]] , ++ p;
return x ? val : ! val;
}
int main()
{
f . getline (init , NM);
int l = strlen (init) , l2 = 0;
while (p < l){
if (init [p] == 'A' && init [p + 1] == 'N')
s [l2] = 'a' , p += 3 , ++ l2;
if (init [p] == 'N' && init [p + 1] == 'O')
s [l2] = 'n' , p += 3 , ++ l2;
if (init [p] == 'O' && init [p + 1] == 'R')
s [l2] = 'o' , p += 2 , ++ l2;
if (init [p] == 'T' && init [p + 1] == 'R')
s [l2] = '1' , p += 4 , ++ l2;
if(init [p] == 'F' && init [p + 1] == 'A')
s [l2] = '0' , p += 5 , ++ l2;
if (init [p] != ' ')
s [l2] = init [p] , ++ l2;
++ p;
}
p = 0;
int t;
f >> t;
f . get ();
while (t --){
char c = f . get ();
v [c] = ! v [c];
p = 0;
g << exp ();
}
return 0;
}